Compare commits

...

2 Commits

Author SHA1 Message Date
YeonGyu-Kim
efb1542a39 fix: empty-prompt error now returns non-null hint via newline-delimited usage string
claw '' and claw '   ' returned empty_prompt + hint:null because the
error message had no newline delimiter. Added usage hint. 61 CLI
contract tests pass.
2026-05-27 16:34:37 +09:00
YeonGyu-Kim
bff370003b fix: plugins extra-arg errors now return non-null hint via newline-delimited usage string
Parity with #791 (config extra-arg fix). The plugins arg parser emitted
'unexpected extra arguments after claw plugins show ...' with no newline
delimiter, so split_error_hint returned None. Added usage hint after newline.
60 CLI contract tests pass.
2026-05-27 15:04:03 +09:00
2 changed files with 82 additions and 2 deletions

View File

@@ -1185,8 +1185,9 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
let action = tail.first().cloned();
let target = tail.get(1).cloned();
if tail.len() > 2 {
// #797: append \n usage hint so split_error_hint extracts it (parity with #791 config fix)
return Err(format!(
"unexpected extra arguments after `claw {} {}`: {}",
"unexpected extra arguments after `claw {} {}`: {}\nUsage: claw plugins [list|show <id>|install <id>|enable <id>|disable <id>|uninstall <id>|update <id>|help]",
rest[0],
tail[..2].join(" "),
tail[2..].join(" ")
@@ -1377,8 +1378,9 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
// an empty prompt when credentials are present).
let joined = rest.join(" ");
if joined.trim().is_empty() {
// #798: add \n hint so split_error_hint extracts it (was empty_prompt + null)
return Err(
"empty prompt: provide a subcommand (run `claw --help`) or a non-empty prompt string"
"empty prompt: provide a subcommand or a non-empty prompt string.\nUsage: claw <subcommand> or claw -p <prompt>. Run `claw --help` for the full list."
.to_string(),
);
}

View File

@@ -3373,3 +3373,81 @@ fn skills_show_extra_positional_arg_returns_unexpected_extra_796() {
"hint should reference usage (#796)"
);
}
#[test]
fn plugins_extra_args_have_non_null_hint_797() {
// #797: `claw plugins show <name> <extra>` returned unexpected_extra_args + hint:null.
// The plugins arg parser at the top level emitted "unexpected extra arguments after
// `claw plugins show ...`: ..." with no \n delimiter. Parity with #791 config fix.
let root = unique_temp_dir("plugins-extra-args-797");
fs::create_dir_all(&root).expect("temp dir");
std::process::Command::new("git")
.args(["init", "-q"])
.current_dir(&root)
.output()
.ok();
let output = run_claw(
&root,
&[
"--output-format",
"json",
"plugins",
"show",
"some-plugin",
"extra-arg",
],
&[],
);
assert!(
!output.status.success(),
"plugins show with extra arg must exit non-zero (#797)"
);
let stderr = String::from_utf8_lossy(&output.stderr);
let j: serde_json::Value = stderr
.lines()
.find(|l| l.trim_start().starts_with('{'))
.and_then(|l| serde_json::from_str(l).ok())
.expect("plugins extra arg should emit JSON error");
assert_eq!(j["error_kind"], "unexpected_extra_args");
let h = j["hint"]
.as_str()
.expect("unexpected_extra_args must have non-null hint (#797)");
assert!(
h.contains("plugins") || h.contains("Usage"),
"hint should reference plugins usage, got: {h:?}"
);
}
#[test]
fn empty_prompt_has_non_null_hint_798() {
// #798: `claw --output-format json ""` returned empty_prompt + hint:null.
// The error message "empty prompt: provide a subcommand..." had no \n delimiter.
let root = unique_temp_dir("empty-prompt-798");
fs::create_dir_all(&root).expect("temp dir");
std::process::Command::new("git")
.args(["init", "-q"])
.current_dir(&root)
.output()
.ok();
let output = run_claw(&root, &["--output-format", "json", ""], &[]);
assert!(
!output.status.success(),
"empty prompt must exit non-zero (#798)"
);
let stderr = String::from_utf8_lossy(&output.stderr);
let j: serde_json::Value = stderr
.lines()
.find(|l| l.trim_start().starts_with('{'))
.and_then(|l| serde_json::from_str(l).ok())
.expect("empty prompt should emit JSON error envelope");
assert_eq!(j["error_kind"], "empty_prompt");
let h = j["hint"]
.as_str()
.expect("empty_prompt must have non-null hint (#798)");
assert!(
h.contains("claw") || h.contains("Usage"),
"hint should reference usage, got: {h:?}"
);
}