From a5c96bcf701d3c1c3f568cae4a4f34913bd63d8b Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 22 Nov 2024 15:05:08 +0900 Subject: [PATCH] settings: simply forward .get_(key) to .get::(key) There's a subtle difference in error message, but the conversion function to be called is the same. The error message now includes "for key ", which is nice. --- cli/tests/test_global_opts.rs | 17 +++++++++++++++++ lib/src/settings.rs | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli/tests/test_global_opts.rs b/cli/tests/test_global_opts.rs index 6844e45ca6..475d388dfa 100644 --- a/cli/tests/test_global_opts.rs +++ b/cli/tests/test_global_opts.rs @@ -592,6 +592,23 @@ fn test_invalid_config() { "###); } +#[test] +fn test_invalid_config_value() { + // Test that we get a reasonable error if a config value is invalid + let test_env = TestEnvironment::default(); + test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); + let repo_path = test_env.env_root().join("repo"); + + let stderr = test_env.jj_cmd_failure( + &repo_path, + &["status", "--config-toml=snapshot.auto-track=[0]"], + ); + insta::assert_snapshot!(stderr, @r" + Config error: invalid type: sequence, expected a string for key `snapshot.auto-track` + For help, see https://martinvonz.github.io/jj/latest/config/. + "); +} + #[test] fn test_no_user_configured() { // Test that the user is reminded if they haven't configured their name or email diff --git a/lib/src/settings.rs b/lib/src/settings.rs index 71238c7dd2..61fb5f9533 100644 --- a/lib/src/settings.rs +++ b/lib/src/settings.rs @@ -265,17 +265,17 @@ impl UserSettings { /// Looks up string value by `key`. pub fn get_string(&self, key: &str) -> Result { - self.get(key).and_then(config::Value::into_string) + self.get(key) } /// Looks up integer value by `key`. pub fn get_int(&self, key: &str) -> Result { - self.get(key).and_then(config::Value::into_int) + self.get(key) } /// Looks up boolean value by `key`. pub fn get_bool(&self, key: &str) -> Result { - self.get(key).and_then(config::Value::into_bool) + self.get(key) } }