{"record":{"id":"f3fca83165acdfec","repo":"nikivdev/code","slug":"suggested-command-is-empty","errorCode":null,"errorMessage":"Suggested command is empty.","messagePattern":"Suggested command is empty\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ask.rs","lineNumber":251,"sourceCode":"        \"Run this command now?\".to_string(),\n        command.trim().to_string(),\n    ];\n    if !confirm_with_tui(\"Ask\", &lines, \"Run suggested command? [Y/n]: \")? {\n        return Ok(());\n    }\n\n    execute_suggested_command(command)\n}\n\nfn execute_suggested_command(command: &str) -> Result<()> {\n    let tokens = shell_words::split(command).unwrap_or_else(|_| {\n        command\n            .split_whitespace()\n            .map(|part| part.to_string())\n            .collect()\n    });\n    if tokens.is_empty() {\n        bail!(\"Suggested command is empty.\");\n    }\n\n    let args = match tokens.first().map(|token| token.as_str()) {\n        Some(\"f\") | Some(\"flow\") => tokens[1..].to_vec(),\n        _ => tokens,\n    };\n    if args.is_empty() {\n        bail!(\"Suggested command is incomplete.\");\n    }\n\n    let exe = std::env::current_exe()?;\n    let status = Command::new(&exe)\n        .args(&args)\n        .stdin(Stdio::inherit())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .with_context(|| format!(\"failed to execute suggested command via {}\", exe.display()))?;","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/ask.rs#L233-L269","documentation":"Thrown by execute_suggested_command in ask.rs when the AI-suggested command string, after splitting on whitespace, produces no tokens — meaning the suggestion was empty or whitespace-only. This is a defensive check before attempting to dispatch the command.","triggerScenarios":"maybe_offer_execute passes an AI suggestion to execute_suggested_command where command is \"\" or \"   \", so tokens.is_empty() triggers the bail.","commonSituations":"AI model returns an empty command field; prompt/response parsing strips everything; upstream truncation leaves only whitespace; a suggestion template whose placeholder was never filled.","solutions":["Verify the AI response actually contains a non-empty command before offering execution","Regenerate or re-prompt if the suggestion came back empty","Handle the empty case upstream (skip execute_suggested_command) instead of passing blank strings"],"exampleFix":"// before\nexecute_suggested_command(&suggestion.command)?;\n// after\nif !suggestion.command.trim().is_empty() {\n    execute_suggested_command(&suggestion.command)?;\n}","handlingStrategy":"validation","validationCode":"fn suggestion_usable(cmd: &str) -> bool {\n    !cmd.split_whitespace().next().unwrap_or(\"\").is_empty()\n}\nif !suggestion_usable(&suggestion.command) {\n    eprintln!(\"skipping empty AI suggestion\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"match execute_suggested_command(&cmd) {\n    Err(e) if e.to_string().contains(\"Suggested command is empty\") => {\n        eprintln!(\"AI returned no command; re-prompt or skip.\");\n        Ok(())\n    }\n    other => other,\n}","preventionTips":["Check suggestion.command.trim() is non-empty before offering execution","Validate AI responses structurally before dispatching commands","Skip gracefully rather than erroring when the suggestion is blank"],"tags":["validation","empty-input","ai-suggestion","cli"],"backgroundTag":"empty-required-argument","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}