jdx/mise · error

`launchctl ` failed

Error message

`launchctl {}` failed: {}

What it means

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.

Solutions

  1. Read the stderr in the error message — it names launchctl's actual complaint and fix that first.
  2. Verify the plist path exists, is owned by the target user, and is valid (`plutil -lint <plist>`).
  3. Use the correct domain prefix (e.g. `gui/$(id -u)/`) for user agents; system services need root.
  4. For bootout failures because the service isn't loaded, treat it as already-removed or check the label spelling.
  5. Run the same command manually in a Terminal to reproduce outside the library.
Defensive patterns

Strategy: try-catch

Validate before calling

# shell
echo $USER && launchctl print gui/$(id -u) >/dev/null 2>&1 && echo domain-ok
plutil -lint ~/Library/LaunchAgents/your.plist

Try / catch

match launchctl_result {
  Err(e) if e.to_string().contains("launchctl") => {
    log::warn!("launchctl failed: {e}; inspect stderr in message");
    // fall back to manual bootstrap or report to user
  }
  Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: `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).

Common situations: 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.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/5efa25a78d86e0d4. Report an issue: GitHub.

Appendix: source

Thrown at src/system/launchd.rs:604

        .stdin(Stdio::null())
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .status()
        .await?;
    Ok(output.success())
}

async fn launchctl(args: &[String]) -> Result<()> {
    debug!("$ launchctl {}", shell_words::join(args));
    let output = tokio::process::Command::new("launchctl")
        .args(args)
        .stdin(Stdio::null())
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .output()
        .await?;
    if !output.status.success() {
        bail!(
            "`launchctl {}` failed: {}",
            shell_words::join(args),
            String::from_utf8_lossy(&output.stderr).trim()
        );
    }
    Ok(())
}

async fn bootout(domain: &str, path: &Path) -> Result<()> {
    let args = [
        "bootout".to_string(),
        domain.to_string(),
        path.to_string_lossy().to_string(),
    ];
    match launchctl(&args).await {
        Ok(()) => Ok(()),
        Err(err) if bootout_missing_error(&err.to_string()) => Ok(()),
        Err(err) => Err(err),

View on GitHub (pinned to 533346cc37)