{"record":{"id":"5efa25a78d86e0d4","repo":"jdx/mise","slug":"launchctl-failed","errorCode":null,"errorMessage":"`launchctl {}` failed: {}","messagePattern":"`launchctl (.+?)` failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/launchd.rs","lineNumber":604,"sourceCode":"        .stdin(Stdio::null())\n        .stdout(Stdio::null())\n        .stderr(Stdio::null())\n        .status()\n        .await?;\n    Ok(output.success())\n}\n\nasync fn launchctl(args: &[String]) -> Result<()> {\n    debug!(\"$ launchctl {}\", shell_words::join(args));\n    let output = tokio::process::Command::new(\"launchctl\")\n        .args(args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .output()\n        .await?;\n    if !output.status.success() {\n        bail!(\n            \"`launchctl {}` failed: {}\",\n            shell_words::join(args),\n            String::from_utf8_lossy(&output.stderr).trim()\n        );\n    }\n    Ok(())\n}\n\nasync fn bootout(domain: &str, path: &Path) -> Result<()> {\n    let args = [\n        \"bootout\".to_string(),\n        domain.to_string(),\n        path.to_string_lossy().to_string(),\n    ];\n    match launchctl(&args).await {\n        Ok(()) => Ok(()),\n        Err(err) if bootout_missing_error(&err.to_string()) => Ok(()),\n        Err(err) => Err(err),","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/launchd.rs#L586-L622","documentation":"Thrown when an invoked `launchctl` subcommand exits with a non-zero status. The error includes the full shell-quoted command (`launchctl <args>`) and launchctl's captured stderr, so the underlying launchd failure (bad plist path, nonexistent service label, permission issues) is surfaced directly. Raised from the shared `launchctl` helper used by apply and bootout operations.","triggerScenarios":"`launchctl bootstrap`/`apply` with a plist that launchd rejects (invalid plist, wrong ownership, domain unavailable); `launchctl bootout` of a label/domain that doesn't exist; running without the privileges launchctl requires for the target domain (e.g. gui vs system).","commonSituations":"Installing/removing a user agent while the GUI session domain is unavailable (SSH without Aqua session); plist syntax errors macOS rejects; attempting to unload a service already unloaded; SIP/permissions preventing system-domain operations.","solutions":["Read the stderr in the error message — it names launchctl's actual complaint and fix that first.","Verify the plist path exists, is owned by the target user, and is valid (`plutil -lint <plist>`).","Use the correct domain prefix (e.g. `gui/$(id -u)/`) for user agents; system services need root.","For bootout failures because the service isn't loaded, treat it as already-removed or check the label spelling.","Run the same command manually in a Terminal to reproduce outside the library."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# shell\necho $USER && launchctl print gui/$(id -u) >/dev/null 2>&1 && echo domain-ok\nplutil -lint ~/Library/LaunchAgents/your.plist","typeGuard":null,"tryCatchPattern":"match launchctl_result {\n  Err(e) if e.to_string().contains(\"launchctl\") => {\n    log::warn!(\"launchctl failed: {e}; inspect stderr in message\");\n    // fall back to manual bootstrap or report to user\n  }\n  Err(e) => return Err(e),\n}","preventionTips":["Lint plists with `plutil -lint` before installing.","Use the correct launchctl domain (gui/$UID) for user agents.","For idempotent teardown, tolerate bootout failures when the service is already unloaded.","Run launchctl manually once to confirm the environment supports it."],"tags":["macos","launchd","launchctl","subprocess"],"backgroundTag":"command-not-found","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}