{"record":{"id":"5a71c292d256b137","repo":"tinyhumansai/openhuman","slug":"command-failed-with-status","errorCode":null,"errorMessage":"command failed with status {}","messagePattern":"command failed with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/platform/service/common.rs","lineNumber":132,"sourceCode":"}\n\n#[cfg(not(windows))]\nfn no_window(_cmd: &mut Command) {}\n\npub(crate) fn run_checked(cmd: &mut Command) -> Result<()> {\n    no_window(cmd);\n    let status = cmd.status()?;\n    if !status.success() {\n        anyhow::bail!(\"command failed with status {status}\");\n    }\n    Ok(())\n}\n\npub(crate) fn run_capture(cmd: &mut Command) -> Result<String> {\n    no_window(cmd);\n    let output = cmd.output()?;\n    if !output.status.success() {\n        anyhow::bail!(\"command failed with status {}\", output.status);\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).to_string())\n}\n\npub(crate) fn run_best_effort(cmd: &mut Command) {\n    no_window(cmd);\n    match cmd.stdout(Stdio::null()).stderr(Stdio::null()).status() {\n        Ok(status) => {\n            if !status.success() {\n                log::debug!(\"[service] best-effort command failed with status {status}\");\n            }\n        }\n        Err(err) => {\n            log::debug!(\"[service] best-effort command failed to execute: {err}\");\n        }\n    }\n}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/platform/service/common.rs#L114-L150","documentation":"run_capture is run_checked's capturing sibling, used where the service command's stdout is parsed (status queries such as launchctl print or systemctl status): a non-zero exit bails with the status, and unlike the success path, both stdout and stderr are discarded on failure — the real reason must be found by rerunning the command manually.","triggerScenarios":"Status-query commands failing: launchctl print on restricted macOS environments (the macOS module keeps a fallback for exactly this), systemctl status against a dead or masked unit, sc query against a service that was removed — commonly hit while polling status during install/uninstall transitions.","commonSituations":"Status polling after a crashed or uninstalled service; macOS contexts without a GUI session; races where status is queried mid-uninstall so the unit no longer exists.","solutions":["Rerun the underlying command manually with stderr visible to get the real message.","Treat status-query failure as degraded rather than fatal — the service may simply not be installed.","For transition races, retry the status query once after a short delay before concluding failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before shelling out to query status, confirm the service is installed at all\n// (uninstalled ⇒ the status command exits non-zero by design)\nlet unit = std::env::var(\"HOME\").ok()\n    .map(|h| std::path::PathBuf::from(h).join(\".config/systemd/user/openhuman-core.service\"));\nif unit.as_ref().map(|p| !p.exists()).unwrap_or(false) {\n    // report NotInstalled instead of running the command\n}","typeGuard":null,"tryCatchPattern":"Wrap status queries so a non-zero exit maps to a NotInstalled/Degraded state in the UI instead of an error toast; on the retry path, capture stderr with .output() so the reason is not lost.","preventionTips":["Guard status calls behind an installed-check.","Do not poll status in tight loops during install/uninstall transitions.","Log which command produced a given status to make triage possible."],"tags":["service","subprocess","exit-status","status-query"],"backgroundTag":"subprocess-non-zero-exit","analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}