{"record":{"id":"fd9cc40883b02199","repo":"santifer/career-ops","slug":"plugins-local-id-already-exists-node-plugins","errorCode":null,"errorMessage":"plugins.local/${id} already exists — `node plugins.mjs remove ${id}` first","messagePattern":"plugins\\.local/(.+?) already exists — `node plugins\\.mjs remove (.+?)` first","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugin-install.mjs","lineNumber":82,"sourceCode":"  // validateManifest wants the dir to BE the plugin dir + the basename to equal id.\n  const tmpNamed = path.join(path.dirname(dir), expectId);\n  if (dir !== tmpNamed) { try { renameSync(dir, tmpNamed); dir = tmpNamed; } catch { /* validate in place using expectId */ } }\n  const manifest = validateManifest(parsed, dir, expectId);\n  if (!manifest) return { ok: false, problems: ['manifest failed validation (see ⚠️ above)'], manifest: null, dir };\n  const audit = auditPlugin(dir);\n  if (!audit.ok) return { ok: false, problems: audit.findings.map(f => `${f.file}: ${f.issue}`), manifest, dir };\n  return { ok: true, problems: [], manifest, dir };\n}\n\n/**\n * Install a community plugin from a github repo at a pinned SHA into\n * plugins.local/<id>. Returns { id, manifest, integrity, dir } WITHOUT enabling\n * it (the caller runs the consent gate). Throws on any validation failure.\n */\nexport function installFromRepo(root, { url, sha }) {\n  const { url: safeUrl, id } = parseRepoArg(url);\n  const dest = path.join(root, 'plugins.local', id);\n  if (existsSync(dest)) throw new Error(`plugins.local/${id} already exists — \\`node plugins.mjs remove ${id}\\` first`);\n  let cloned = safeClone(safeUrl, sha);\n  let result;\n  try { result = validateInstall(cloned, id); }\n  catch (e) { rmSync(cloned, { recursive: true, force: true }); throw e; }\n  if (!result.ok) {\n    rmSync(result.dir || cloned, { recursive: true, force: true });\n    throw new Error(`plugin rejected:\\n  - ${result.problems.join('\\n  - ')}`);\n  }\n  mkdirSync(path.join(root, 'plugins.local'), { recursive: true });\n  cpSync(result.dir, dest, { recursive: true });\n  rmSync(result.dir, { recursive: true, force: true });\n  const tree = hashPluginTree(dest);\n  return { id, manifest: { ...result.manifest, dir: dest }, integrity: tree.integrity, files: tree.files, repo: safeUrl, sha };\n}\n\n/**\n * Clone + statically validate a registry entry WITHOUT installing it (used by\n * the registry-validate CI). Executes NO plugin code — manifest is parsed, the","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/plugin-install.mjs#L64-L100","documentation":"Thrown by installFromRepo() when the destination plugins.local/<id> already exists at install time. Re-installing over an existing plugin would silently change its code/version without going through the explicit remove → reinstall flow, so the operation fails fast and tells the user how to proceed.","triggerScenarios":"Running install twice without removing; a plugin with the same id was scaffolded locally earlier; a previous failed install left a partial plugins.local/<id> directory.","commonSituations":"Iterating on plugin install during development; reinstalling to bump a SHA; a prior install was interrupted after cpSync created the dest dir.","solutions":["Run `node plugins.mjs remove <id>` first, then reinstall.","If the existing dir is a leftover from a failed install, remove it manually or via the remove command.","Use a different plugin name/id if you want both copies.","Confirm you are not reinstalling the same plugin unintentionally."],"exampleFix":"// before: re-run install over existing\ncpSync(result.dir, dest); // throws: already exists\n// after: remove then install\n// `node plugins.mjs remove my-plugin`\n// `node plugins.mjs install <repo> --sha <sha>`","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\nimport path from 'path';\nfunction pluginInstalled(root, id) {\n  return existsSync(path.join(root, 'plugins.local', id));\n}\nif (pluginInstalled(root, id)) {\n  // prompt: remove first, or pick a different id\n}","typeGuard":"null","tryCatchPattern":"try {\n  installFromRepo(root, { url, sha });\n} catch (e) {\n  if (/already exists/.test(e.message)) {\n    // run `node plugins.mjs remove <id>` then retry\n  } else throw e;\n}","preventionTips":["Check `node plugins.mjs list` before installing to detect id collisions.","Always remove before reinstalling to keep state explicit.","Clean up partial installs left by interrupted runs."],"tags":["plugins","filesystem","idempotency","install"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}