Skip to content

Commit

Permalink
feat: add keyword argument name in error message (#779)
Browse files Browse the repository at this point in the history
* fix: make fmt

Signed-off-by: zongz <[email protected]>

* feat: add keyword argument name in error message

Signed-off-by: zongz <[email protected]>

---------

Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe authored Oct 17, 2023
1 parent 6e02ee7 commit db59124
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions kclvm/cmd/src/test_data/failed/keyword_argument_error.k
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = "{ID}".format(2) # keyword argument not found -> keyword argument 'ID' not found
22 changes: 20 additions & 2 deletions kclvm/cmd/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(&[
Expand All @@ -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(&[
Expand All @@ -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"));
}
}
}
2 changes: 1 addition & 1 deletion kclvm/runtime/src/value/val_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit db59124

Please sign in to comment.