affaan-m/ECC · error
Failed to save package manager preference
Error message
Failed to save package manager preference: ${err.message} What it means
After validating the package manager name, setPreferredPackageManager persists the choice via saveConfig; if persistence fails, the original error is wrapped as 'Failed to save package manager preference: <reason>'. The write step is intentionally guarded so I/O problems surface with context.
Solutions
- Read the appended err.message to identify the underlying cause (EACCES, ENOSPC, EROFS, syntax error).
- Ensure the config directory exists and is writable by the current user (check ownership of ~/.claude).
- Fix or delete a corrupted config file so saveConfig can rewrite it.
- Free disk space if the error indicates ENOSPC, then retry the setter.
Example fix
// before
setPreferredPackageManager('pnpm'); // throws: Failed to save... EACCES
// after
try {
setPreferredPackageManager('pnpm');
} catch (e) {
console.error('Config write failed:', e.message); // inspect underlying cause
fs.mkdirSync(configDir, { recursive: true });
setPreferredPackageManager('pnpm');
} Defensive patterns
Strategy: try-catch
Validate before calling
import fs from 'node:fs'; const configDir = os.homedir() + '/.claude'; fs.accessSync(configDir, fs.constants.W_OK); // throws early if not writable
Type guard
null
Try / catch
try {
setPreferredPackageManager('pnpm');
} catch (e) {
if (e.message.startsWith('Failed to save package manager preference')) {
// inspect e.message for EACCES/ENOSPC/EROFS and remediate
console.error(e.message);
} else throw e;
} Prevention
- Verify the global config directory exists and is writable before setting preferences
- Watch for read-only home/NFS mounts in containers
- Fix corrupted config files promptly instead of retrying blindly
- Surface the wrapped err.message in your tooling for diagnosis
When it happens
Trigger: saveConfig throws because the config directory is missing/unwritable, a permission error occurs on ~/.claude or the config file, or the disk is full. The inner err.message is appended to the thrown message.
Common situations: Read-only home directory or NFS mount; ~/.claude path owned by another user; corrupted config JSON that saveConfig cannot rewrite; running in a container with a read-only filesystem.
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
- Failed to save package manager config to
- gate.variant_missing
- Install manifests not found under
- memory connector path is not a directory
- state.reason
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/da0409b431590f21.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/lib/package-manager.js:256
};
}
/**
* Set user's preferred package manager (global)
*/
function setPreferredPackageManager(pmName) {
if (!PACKAGE_MANAGERS[pmName]) {
throw new Error(`Unknown package manager: ${pmName}`);
}
const config = loadConfig() || {};
config.packageManager = pmName;
config.setAt = new Date().toISOString();
try {
saveConfig(config);
} catch (err) {
throw new Error(`Failed to save package manager preference: ${err.message}`);
}
return config;
}
/**
* Set project's preferred package manager
*/
function setProjectPackageManager(pmName, projectDir = process.cwd()) {
if (!PACKAGE_MANAGERS[pmName]) {
throw new Error(`Unknown package manager: ${pmName}`);
}
const configDir = path.join(projectDir, '.claude');
const configPath = path.join(configDir, 'package-manager.json');
const config = {
packageManager: pmName,View on GitHub (pinned to 8321021c54)