Skip to content

Commit

Permalink
config: construct "unset" error without using config::ConfigError
Browse files Browse the repository at this point in the history
I also changed the error type from Config to User. They are failures of user
action, not configuration.
  • Loading branch information
yuja committed Dec 10, 2024
1 parent 1c7634f commit fc04cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,11 @@ pub fn remove_config_value_from_file(
let target_table = key_iter.try_fold(doc.as_table_mut(), |table, key| {
table
.get_mut(key)
.ok_or_else(|| ConfigError::NotFound(key.to_string()))
.ok_or_else(|| user_error(format!(r#""{key}" doesn't exist"#)))
.and_then(|table| {
table
.as_table_mut()
.ok_or_else(|| ConfigError::Message(format!(r#""{key}" is not a table"#)))
.ok_or_else(|| user_error(format!(r#""{key}" is not a table"#)))
})
})?;

Expand All @@ -510,7 +510,7 @@ pub fn remove_config_value_from_file(
entry.remove();
}
toml_edit::Entry::Vacant(_) => {
return Err(ConfigError::NotFound(key.to_string()).into());
return Err(user_error(format!(r#""{key}" doesn't exist"#)));
}
}

Expand Down
10 changes: 2 additions & 8 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,7 @@ fn test_config_unset_non_existent_key() {
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_failure(&repo_path, &["config", "unset", "--user", "nonexistent"]);
insta::assert_snapshot!(stderr, @r###"
Config error: configuration property "nonexistent" not found
For help, see https://martinvonz.github.io/jj/latest/config/.
"###);
insta::assert_snapshot!(stderr, @r#"Error: "nonexistent" doesn't exist"#);
}

#[test]
Expand All @@ -637,10 +634,7 @@ fn test_config_unset_inline_table_key() {
&["config", "unset", "--user", "inline-table.foo"],
);

insta::assert_snapshot!(stderr, @r###"
Config error: "inline-table" is not a table
For help, see https://martinvonz.github.io/jj/latest/config/.
"###);
insta::assert_snapshot!(stderr, @r#"Error: "inline-table" is not a table"#);
}

#[test]
Expand Down

0 comments on commit fc04cdb

Please sign in to comment.