{"record":{"id":"d16db9a40d855eb5","repo":"sigoden/aichat","slug":"unable-to-run-cmd-name-err","errorCode":null,"errorMessage":"Unable to run {cmd_name}, {err}","messagePattern":"Unable to run (.+?), (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/function.rs","lineNumber":280,"sourceCode":"    bin_dirs.push(Config::functions_bin_dir());\n    let current_path = std::env::var(\"PATH\").context(\"No PATH environment variable\")?;\n    let prepend_path = bin_dirs\n        .iter()\n        .map(|v| format!(\"{}{PATH_SEP}\", v.display()))\n        .collect::<Vec<_>>()\n        .join(\"\");\n    envs.insert(\"PATH\".into(), format!(\"{prepend_path}{current_path}\"));\n\n    let temp_file = temp_file(\"-eval-\", \"\");\n    envs.insert(\"LLM_OUTPUT\".into(), temp_file.display().to_string());\n\n    #[cfg(windows)]\n    let cmd_name = polyfill_cmd_name(&cmd_name, &bin_dirs);\n    if *IS_STDOUT_TERMINAL {\n        println!(\"{}\", dimmed_text(&prompt));\n    }\n    let exit_code = run_command(&cmd_name, &cmd_args, Some(envs))\n        .map_err(|err| anyhow!(\"Unable to run {cmd_name}, {err}\"))?;\n    if exit_code != 0 {\n        bail!(\"Tool call exit with {exit_code}\");\n    }\n    let mut output = None;\n    if temp_file.exists() {\n        let contents =\n            fs::read_to_string(temp_file).context(\"Failed to retrieve tool call output\")?;\n        if !contents.is_empty() {\n            output = Some(contents);\n        }\n    };\n    Ok(output)\n}\n\n#[cfg(windows)]\nfn polyfill_cmd_name<T: AsRef<Path>>(cmd_name: &str, bin_dir: &[T]) -> String {\n    let cmd_name = cmd_name.to_string();\n    if let Ok(exts) = std::env::var(\"PATHEXT\") {","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/function.rs#L262-L298","documentation":"run_llm_function shells out to an external command; if spawning fails (binary missing, permission denied, IO error) the underlying error is wrapped with the command name. Non-zero exits produce a separate 'Tool call exit with N' error instead.","triggerScenarios":"run_llm_function invoked (via run_instructions_fn or eval) and run_command returns Err — the executable isn't found on PATH or in bin_dirs, or can't be executed.","commonSituations":"Tool command not installed; PATH missing the tool's bin dir on the current platform; Windows polyfill_cmd_name failing to locate a .cmd/.exe shim; insufficient execute permissions.","solutions":["Install the command or add its directory to PATH / the configured bin_dirs","Verify the tool name spelling in the function definition","Check file permissions (chmod +x) on the executable"],"exampleFix":"// before: cmd not installed\n// after\n$ cargo install the-tool  # or: export PATH=\"$PATH:/path/to/tool/bin\"","handlingStrategy":"try-catch","validationCode":"fn tool_available(cmd: &str, bin_dirs: &[PathBuf]) -> bool {\n    which::which(cmd).is_ok() || bin_dirs.iter().any(|d| d.join(cmd).exists())\n}","typeGuard":null,"tryCatchPattern":"match run_llm_function(f).await {\n    Err(e) if e.to_string().starts_with(\"Unable to run\") => {\n        eprintln!(\"Tool not available: {e}\"); install_hint();\n    }\n    other => other?,\n}","preventionTips":["Check tool availability with `which`/`where` before invoking","Include the tool's bin dir in PATH or the config's bin_dirs","Pin tool installations in your environment setup scripts"],"tags":["command-execution","process","path"],"backgroundTag":"command-not-found","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}