jdx/mise · error
failed to synchronize macOS preference domain
Error message
failed to synchronize macOS preference domain {domain} What it means
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.
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.
Defensive patterns
Strategy: try-catch
Validate before calling
if !cfg!(target_os = "macos") { return; }
let plist = std::env::home_dir().map(|h| h.join("Library/Preferences")).unwrap();
assert!(fs::metadata(&plist).map(|m| !m.permissions().readonly()).unwrap_or(false), "preferences dir not writable"); Try / catch
match defaults::write_all(&requests) {
Err(e) if e.to_string().contains("failed to synchronize macOS preference domain") => {
// notify user to check cfprefsd/disk, optionally retry once
}
Err(e) => return Err(e),
Ok(()) => {}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- changed during application; left untouched
- changed during recovery; left untouched
- is not a directory; resolve its type before pulling
- is not a regular file or symlink
- a parent directory is now a symlink; left untouched
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/1bdc1d53f57dcaeb.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/defaults.rs:582
unsafe {
CFPreferencesSetValue(
key.as_concrete_TypeRef(),
value.as_CFTypeRef(),
application_id,
kCFPreferencesCurrentUser,
host_id(host),
);
}
Ok(())
}
fn synchronize(domain: &str, host: HostScope) -> Result<()> {
let (_application, application_id) = application_id(domain);
unsafe {
if CFPreferencesSynchronize(application_id, kCFPreferencesCurrentUser, host_id(host))
== 0
{
eyre::bail!("failed to synchronize macOS preference domain {domain}");
}
}
Ok(())
}
pub(super) fn write_all(requests: &[DefaultsRequest]) -> Result<()> {
let mut domains = IndexSet::new();
let writes = prepare_writes(requests, read)?;
for ((domain, key, host), value) in &writes {
set(domain, key, value, *host)?;
domains.insert((domain.as_str(), *host));
}
for (domain, host) in domains {
synchronize(domain, host)?;
}
Ok(())
}
View on GitHub (pinned to 533346cc37)