{"record":{"id":"88d4d4c59d34aa5e","repo":"affaan-m/ECC","slug":"failed-to-save-package-manager-config-to-configp","errorCode":null,"errorMessage":"Failed to save package manager config to ${configPath}: ${err.message}","messagePattern":"Failed to save package manager config to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/package-manager.js","lineNumber":281,"sourceCode":" * Set project's preferred package manager\n */\nfunction setProjectPackageManager(pmName, projectDir = process.cwd()) {\n  if (!PACKAGE_MANAGERS[pmName]) {\n    throw new Error(`Unknown package manager: ${pmName}`);\n  }\n\n  const configDir = path.join(projectDir, '.claude');\n  const configPath = path.join(configDir, 'package-manager.json');\n\n  const config = {\n    packageManager: pmName,\n    setAt: new Date().toISOString()\n  };\n\n  try {\n    writeFile(configPath, JSON.stringify(config, null, 2));\n  } catch (err) {\n    throw new Error(`Failed to save package manager config to ${configPath}: ${err.message}`);\n  }\n  return config;\n}\n\n// Allowed characters in script/binary names: alphanumeric, dash, underscore, dot, slash, @\n// This prevents shell metacharacter injection while allowing scoped packages (e.g., @scope/pkg)\nconst SAFE_NAME_REGEX = /^[@a-zA-Z0-9_./-]+$/;\n\n/**\n * Get the command to run a script\n * @param {string} script - Script name (e.g., \"dev\", \"build\", \"test\")\n * @param {object} options - { projectDir }\n * @throws {Error} If script name contains unsafe characters\n */\nfunction getRunCommand(script, options = {}) {\n  if (!script || typeof script !== 'string') {\n    throw new Error('Script name must be a non-empty string');\n  }","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/package-manager.js#L263-L299","documentation":"After building the project config object, setProjectPackageManager writes it to <projectDir>/.claude/package-manager.json via writeFile; any write failure is rethrown as 'Failed to save package manager config to <path>: <reason>'. This keeps the original I/O error message attached to a descriptive wrapper.","triggerScenarios":"The .claude directory does not exist (ENOENT since writeFile doesn't mkdir), the project directory is read-only, path permissions deny the write (EACCES), or disk is full (ENOSPC).","commonSituations":"Fresh clones with no .claude directory yet; project dirs mounted read-only in containers; wrong projectDir argument pointing to a non-writable location; running as a user without write access to the repo.","solutions":["Read the wrapped err.message for the root cause (ENOENT/EACCES/ENOSPC).","Create the directory first: fs.mkdirSync(path.join(projectDir, '.claude'), { recursive: true }) then retry setProjectPackageManager.","Ensure projectDir points at the actual project root and the current user has write permission.","In CI, run in a writable workspace or persist the choice another way if the repo is read-only."],"exampleFix":"// before\nsetProjectPackageManager('pnpm', projectDir); // throws ENOENT\n// after\nfs.mkdirSync(path.join(projectDir, '.claude'), { recursive: true });\nsetProjectPackageManager('pnpm', projectDir);","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nconst dir = path.join(projectDir, '.claude');\nfs.mkdirSync(dir, { recursive: true });\nfs.accessSync(dir, fs.constants.W_OK);","typeGuard":"null","tryCatchPattern":"try {\n  setProjectPackageManager('pnpm', projectDir);\n} catch (e) {\n  if (e.message.startsWith('Failed to save package manager config')) {\n    // message includes configPath + cause (ENOENT/EACCES/ENOSPC); remediate and retry\n    console.error(e.message);\n  } else throw e;\n}","preventionTips":["Create the .claude directory with recursive:true before project config writes","Confirm projectDir is the real project root and writable","Handle read-only workspaces in CI by persisting config elsewhere","Include the failing path in your own error reporting for faster diagnosis"],"tags":["filesystem","config","project"],"backgroundTag":"file-write-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}