{"record":{"id":"91f2ce933ac9e8c2","repo":"jdx/mise","slug":"defaults-failed","errorCode":null,"errorMessage":"`defaults {}` failed: {}","messagePattern":"`defaults (.+?)` failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/defaults.rs","lineNumber":227,"sourceCode":"        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .output()\n        .await?;\n    if !output.status.success() {\n        // \"does not exist\" is the expected missing-key/-domain answer;\n        // \"could not find key\" is the same for `read-type`;\n        // \"Domain [...] not found\" is the expected answer when the domain does not exist;\n        // any other failure (cfprefsd unavailable, managed domain, ...) must not\n        // masquerade as Unset\n        static MISSING_KEY_RE: LazyLock<Regex> = LazyLock::new(|| {\n            Regex::new(r\"(?i)does not exist|could not find key|Domain .* not found\").unwrap()\n        });\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        if MISSING_KEY_RE.is_match(&stderr) {\n            return Ok(None);\n        }\n        eyre::bail!(\n            \"`defaults {}` failed: {}\",\n            shell_words::join(args),\n            stderr.trim()\n        );\n    }\n    // strip only the trailing newline — leading/trailing spaces can be\n    // significant in string values\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    Ok(Some(stdout.trim_end_matches(['\\r', '\\n']).to_string()))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    fn val(s: &str) -> toml::Value {\n        s.parse().unwrap()\n    }","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/jdx/mise/blob/6f52dcdf99e282ef7a7db68c81301fa4618d0f79/src/system/defaults.rs#L209-L245","documentation":"Checking current state runs defaults read-type / defaults read. Their most common failure — key or domain absent — matches a regex ('does not exist', 'could not find key', 'Domain ... not found') and maps to a normal Unset state. Any other non-zero exit (cfprefsd unavailable, permission denied, corrupt plist, managed domain) misses the regex and bails with the joined args and stderr instead of masquerading the key as unset — the comment in the code says exactly that.","triggerScenarios":"defaults read failing outside the missing-key cases: no per-user cfprefsd reachable (pure SSH session, no GUI login), a corrupt ~/Library/Preferences plist, or a sandbox blocking IPC to the preferences daemon.","commonSituations":"CI or bootstrap over SSH on macOS before first GUI login; an app crash leaving a truncated plist; running inside a hardened sandbox that denies AppleEvents/preferences IPC.","solutions":["Reproduce with the 'defaults read ...' command shown in the error to see the raw stderr","Run bootstrap from a real GUI login session so cfprefsd is reachable","For a corrupt plist: quit the owning app, remove ~/Library/Preferences/<domain>.plist, re-run mise bootstrap"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# preflight: is the preferences daemon reachable at all?\ndefaults read -g AppleLocale >/dev/null 2>&1 || echo 'cfprefsd unreachable — run bootstrap from a GUI login session'","typeGuard":null,"tryCatchPattern":"Catch non-zero from mise bootstrap and inspect the defaults stderr inside the message: text matching 'does not exist', 'could not find key', or 'Domain ... not found' is a normal Unset; anything else means environment or plist trouble — retry once in a GUI session, and treat corrupt-plist errors as 'delete the plist and re-run'.","preventionTips":["Do not bootstrap macOS defaults from headless SSH before first GUI login","Add a preflight 'defaults read -g AppleLocale' in scripts; if it fails, skip the defaults part and report","After forced shutdowns, suspect corrupt plists — delete and let the app regenerate rather than fighting read errors"],"tags":["mise","macos","defaults","bootstrap","cfprefsd"],"backgroundTag":"macos-defaults-command-failed","analyzedSha":"6f52dcdf99e282ef7a7db68c81301fa4618d0f79","analyzedAt":"2026-08-22T10:14:23.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}