{"record":{"id":"5897ef855e02de8a","repo":"nikivdev/code","slug":"specify-a-task-name-pid-pid-or-all","errorCode":null,"errorMessage":"Specify a task name, --pid <pid>, or --all","messagePattern":"Specify a task name, --pid <pid>, or --all","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/processes.rs","lineNumber":115,"sourceCode":"        format!(\"{}m {}s\", elapsed_secs / 60, elapsed_secs % 60)\n    } else {\n        format!(\"{}h {}m\", elapsed_secs / 3600, (elapsed_secs % 3600) / 60)\n    }\n}\n\n/// Kill processes based on options\npub fn kill_processes(opts: KillOpts) -> Result<()> {\n    let (config_path, _cfg) = tasks::load_project_config(opts.config)?;\n    let canonical = config_path.canonicalize()?;\n\n    if let Some(pid) = opts.pid {\n        kill_by_pid(pid, opts.force, opts.timeout)\n    } else if let Some(task) = &opts.task {\n        kill_by_task(&canonical, task, opts.force, opts.timeout)\n    } else if opts.all {\n        kill_all_for_project(&canonical, opts.force, opts.timeout)\n    } else {\n        bail!(\"Specify a task name, --pid <pid>, or --all\")\n    }\n}\n\nfn kill_by_pid(pid: u32, force: bool, timeout: u64) -> Result<()> {\n    let processes = running::load_running_processes()?;\n\n    // Find the process entry to get its PGID\n    let entry = processes.projects.values().flatten().find(|p| p.pid == pid);\n\n    let pgid = entry.map(|e| e.pgid).unwrap_or(pid);\n    let task_name = entry.map(|e| e.task_name.as_str()).unwrap_or(\"unknown\");\n\n    terminate_process_group(pgid, force, timeout)?;\n    running::unregister_process(pid)?;\n\n    println!(\"Killed {} (pid: {}, pgid: {})\", task_name, pid, pgid);\n    Ok(())\n}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/processes.rs#L97-L133","documentation":"The `kill` command requires the caller to select what to kill: a task name, a PID via --pid, or everything via --all. If none of these is provided, kill_processes bails with this usage guidance instead of guessing. It is a user-input validation error, not an internal failure.","triggerScenarios":"Invoking `f kill` (or calling kill_processes with opts.task=None, opts.pid=None, opts.all=false) — i.e., no targeting flag at all on the command line.","commonSituations":"Typing `f kill` with no arguments, forgetting that task name must be positional, or scripting the command with an empty variable where the task name should be.","solutions":["Pass the task name: `f kill <task>`.","Or target a specific process: `f kill --pid <pid>`.","Or kill everything for the project: `f kill --all`.","List current targets first with `f ps` to decide what to kill."],"exampleFix":"// before (shell script)\nf kill $TASK\n// after\nTASK=\"${TASK:?set TASK or pass an explicit kill target}\"\nf kill \"$TASK\"","handlingStrategy":"validation","validationCode":"// check args before invoking the CLI\nlet args: Vec<String> = std::env::args().skip(1).collect();\nif !args.iter().any(|a| a == \"--all\" || a == \"--pid\") && args.len() < 2 {\n    eprintln!(\"usage: f kill <task> | --pid <pid> | --all\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"match kill_processes(opts) {\n    Ok(()) => (),\n    Err(e) if e.to_string().contains(\"Specify a task name\") => {\n        eprintln!(\"{e}\");\n        std::process::exit(2); // usage error, not a runtime failure\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always pass one of: task name, --pid, or --all.","Add shell completion or a wrapper that rejects empty kill targets.","Guard scripts with ${VAR:?} for interpolated task names/pids."],"tags":["cli","usage","argument-validation","processes"],"backgroundTag":"missing-required-argument","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}