diff --git a/kclvm/cmd/src/test_data/failed/keyword_argument_error.k b/kclvm/cmd/src/test_data/failed/keyword_argument_error.k new file mode 100644 index 000000000..e034af544 --- /dev/null +++ b/kclvm/cmd/src/test_data/failed/keyword_argument_error.k @@ -0,0 +1 @@ +a = "{ID}".format(2) # keyword argument not found -> keyword argument 'ID' not found \ No newline at end of file diff --git a/kclvm/cmd/src/tests.rs b/kclvm/cmd/src/tests.rs index 445889ef9..1779a7550 100644 --- a/kclvm/cmd/src/tests.rs +++ b/kclvm/cmd/src/tests.rs @@ -228,6 +228,9 @@ fn test_run_command() { test_conflict_mod_file(); test_instances_with_yaml(); test_plugin_not_found(); + test_error_message_fuzz_matched(); + test_error_message_fuzz_unmatched(); + test_keyword_argument_error_message(); } fn test_run_command_with_import() { @@ -560,7 +563,6 @@ fn test_plugin_not_found() { } } -#[test] fn test_error_message_fuzz_matched() { let test_case_path = PathBuf::from("./src/test_data/fuzz_match/main.k"); let matches = app().arg_required_else_help(true).get_matches_from(&[ @@ -579,7 +581,6 @@ fn test_error_message_fuzz_matched() { } } -#[test] fn test_error_message_fuzz_unmatched() { let test_case_path = PathBuf::from("./src/test_data/fuzz_match/main_unmatched.k"); let matches = app().arg_required_else_help(true).get_matches_from(&[ @@ -596,3 +597,20 @@ fn test_error_message_fuzz_unmatched() { } } } + +fn test_keyword_argument_error_message() { + let test_case_path = PathBuf::from("./src/test_data/failed/keyword_argument_error.k"); + let matches = app().arg_required_else_help(true).get_matches_from(&[ + ROOT_CMD, + "run", + &test_case_path.canonicalize().unwrap().display().to_string(), + ]); + let settings = must_build_settings(matches.subcommand_matches("run").unwrap()); + let sess = Arc::new(ParseSession::default()); + match exec_program(sess.clone(), &settings.try_into().unwrap()) { + Ok(_) => panic!("unreachable code."), + Err(msg) => { + assert!(msg.contains("keyword argument 'ID' not found")); + } + } +} diff --git a/kclvm/runtime/src/value/val_fmt.rs b/kclvm/runtime/src/value/val_fmt.rs index f23f14844..b702fad00 100644 --- a/kclvm/runtime/src/value/val_fmt.rs +++ b/kclvm/runtime/src/value/val_fmt.rs @@ -901,7 +901,7 @@ impl FormatString { } FieldType::Keyword(keyword) => kwargs .dict_get_value(keyword.as_str()) - .expect("keyword argument not found") + .expect(&format!("keyword argument '{}' not found", keyword)) .clone(), }; for name_part in parts {