jdx/mise · error

failed to synchronize macOS preference domain {domain}

Error message

failed to synchronize macOS preference domain {domain}

What it means

After writing macOS preference keys via CFPreferences (defaults), mise calls CFPreferencesSynchronize to flush the domain to disk. If synchronize returns 0 (failure), the preference domain could not be persisted; this instance is raised from the write path (synchronize, called by write_all).

Source

Thrown at src/system/defaults.rs:367

                value.as_CFTypeRef(),
                application_id,
                kCFPreferencesCurrentUser,
                kCFPreferencesAnyHost,
            );
        }
        Ok(())
    }

    fn synchronize(domain: &str) -> Result<()> {
        let (_application, application_id) = application_id(domain);
        unsafe {
            if CFPreferencesSynchronize(
                application_id,
                kCFPreferencesCurrentUser,
                kCFPreferencesAnyHost,
            ) == 0
            {
                eyre::bail!("failed to synchronize macOS preference domain {domain}");
            }
        }
        Ok(())
    }

    pub(super) fn write_all(requests: &[DefaultsRequest]) -> Result<()> {
        let mut domains = IndexSet::new();
        for request in requests {
            set(&request.domain, &request.key, &request.value)?;
            domains.insert(request.domain.as_str());
        }
        for domain in domains {
            synchronize(domain)?;
        }
        Ok(())
    }

    #[cfg(test)]

View on GitHub (pinned to afd2eddd3a)

Solutions

  1. Check permissions and ownership of ~/Library/Preferences/<domain>.plist
  2. Delete or repair the corrupt plist (e.g. `defaults delete <domain>` or remove the file) and retry
  3. Verify HOME is writable and you are not in a sandbox blocking CFPreferences
  4. Run `defaults read <domain>` to confirm the domain is accessible
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight on macOS
let out = std::process::Command::new("defaults").args(["read", domain]).output()?;
if !out.status.success() { eprintln!("domain unreadable: {}", domain); }

Try / catch

match result {
    Err(e) if e.to_string().contains("failed to synchronize") => {
        // repair plist permissions / delete corrupt plist, then retry
    }
    Err(e) => return Err(e),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: CFPreferencesSynchronize fails while flushing a defaults domain (kCFPreferencesCurrentUser, kCFPreferencesAnyHost) after writing keys, e.g. a malformed or unwritable plist backing the domain.

Common situations: Corrupt or wrong-permission ~/Library/Preferences/<domain>.plist; sandboxed or read-only HOME; domain managed by another process/MDM; disk-full filesystem on macOS.

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


AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09). Data as JSON: /api/errors/1bdc1d53f57dcaeb. Report an issue: GitHub.