{"record":{"id":"1bdc1d53f57dcaeb","repo":"jdx/mise","slug":"failed-to-synchronize-macos-preference-domain-dom","errorCode":null,"errorMessage":"failed to synchronize macOS preference domain {domain}","messagePattern":"failed to synchronize macOS preference domain (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/defaults.rs","lineNumber":582,"sourceCode":"        unsafe {\n            CFPreferencesSetValue(\n                key.as_concrete_TypeRef(),\n                value.as_CFTypeRef(),\n                application_id,\n                kCFPreferencesCurrentUser,\n                host_id(host),\n            );\n        }\n        Ok(())\n    }\n\n    fn synchronize(domain: &str, host: HostScope) -> Result<()> {\n        let (_application, application_id) = application_id(domain);\n        unsafe {\n            if CFPreferencesSynchronize(application_id, kCFPreferencesCurrentUser, host_id(host))\n                == 0\n            {\n                eyre::bail!(\"failed to synchronize macOS preference domain {domain}\");\n            }\n        }\n        Ok(())\n    }\n\n    pub(super) fn write_all(requests: &[DefaultsRequest]) -> Result<()> {\n        let mut domains = IndexSet::new();\n        let writes = prepare_writes(requests, read)?;\n        for ((domain, key, host), value) in &writes {\n            set(domain, key, value, *host)?;\n            domains.insert((domain.as_str(), *host));\n        }\n        for (domain, host) in domains {\n            synchronize(domain, host)?;\n        }\n        Ok(())\n    }\n","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/defaults.rs#L564-L600","documentation":"Thrown by `synchronize` when the Core Foundation call `CFPreferencesSynchronize` returns 0, meaning macOS failed to flush the in-memory preference domain to persistent storage (plist on disk). The library bails with the domain name so you know which preference domain could not be committed. This is a macOS-only operation backed by CFPreferences APIs.","triggerScenarios":"Calling `write_all` (which calls `synchronize(domain, host)`) after writing defaults, and the kernel-level `CFPreferencesSynchronize(application_id, kCFPreferencesCurrentUser, host_id(host))` returns 0 — e.g. the domain/plist is locked, on a read-only volume, or CF cannot resolve the host container.","commonSituations":"Running under a sandboxed/containerized environment without access to `~/Library/Preferences`; disk-full or permissions problems on the preferences plist; a cfprefsd daemon in a bad state; targeting host scopes (ByHost) on systems where that container is unavailable; running in CI on non-macOS hosts emulating the path.","solutions":["Verify the code runs on real macOS with access to ~/Library/Preferences and a healthy cfprefsd (try `defaults read <domain>` and `killall cfprefsd`).","Check disk space and permissions on the preference plist for the domain (~/Library/Preferences/<domain>.plist).","If running in a sandbox/CI container, grant write access to the preferences directory or run the sync on a real user session.","Retry the synchronize after killing cfprefsd (`killall cfprefsd`) so stale state is flushed and restarted."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !cfg!(target_os = \"macos\") { return; }\nlet plist = std::env::home_dir().map(|h| h.join(\"Library/Preferences\")).unwrap();\nassert!(fs::metadata(&plist).map(|m| !m.permissions().readonly()).unwrap_or(false), \"preferences dir not writable\");","typeGuard":null,"tryCatchPattern":"match defaults::write_all(&requests) {\n    Err(e) if e.to_string().contains(\"failed to synchronize macOS preference domain\") => {\n        // notify user to check cfprefsd/disk, optionally retry once\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Run preference sync only on real macOS user sessions, not sandboxed CI containers.","Check disk space and ~/Library/Permissions writability before batch-writing defaults.","Restart cfprefsd if defaults operations start failing unexpectedly."],"tags":["macos","cfpreferences","filesystem","sync"],"backgroundTag":"file-write-failed","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"}