{"record":{"id":"59ee6673b3b26872","repo":"santifer/career-ops","slug":"plugins-local-name-already-exists","errorCode":null,"errorMessage":"plugins.local/${name} already exists","messagePattern":"plugins\\.local/(.+?) already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugin-install.mjs","lineNumber":125,"sourceCode":"  let parsed;\n  try { parsed = parseRepoArg(url); } catch (e) { return [e.message]; }\n  if (expectId && parsed.id !== expectId) return [`repo \"${url}\" → id \"${parsed.id}\" but registry id is \"${expectId}\"`];\n  let dir;\n  try { dir = safeClone(parsed.url, sha); } catch (e) { return [e.message]; }\n  let result;\n  try { result = validateInstall(dir, parsed.id); }\n  catch (e) { rmSync(dir, { recursive: true, force: true }); return [e.message]; }\n  try { rmSync(result.dir || dir, { recursive: true, force: true }); } catch { /* best-effort */ }\n  return result.ok ? [] : result.problems;\n}\n\n/** Scaffold a new local plugin from plugins/_template/. */\nexport function scaffoldNew(root, name) {\n  if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) throw new Error(`plugin name must match [a-z0-9-] (got \"${name}\")`);\n  const tpl = path.join(root, 'plugins', '_template');\n  if (!existsSync(tpl)) throw new Error('plugins/_template/ not found');\n  const dest = path.join(root, 'plugins.local', name);\n  if (existsSync(dest)) throw new Error(`plugins.local/${name} already exists`);\n  mkdirSync(path.join(root, 'plugins.local'), { recursive: true });\n  cpSync(tpl, dest, { recursive: true });\n  // Substitute {{NAME}} placeholders in shipped text files.\n  const sub = (p) => { if (existsSync(p)) writeFileSync(p, readFileSync(p, 'utf8').replaceAll('{{NAME}}', name), 'utf8'); };\n  for (const f of readdirSync(dest, { withFileTypes: true })) {\n    if (f.isFile()) sub(path.join(dest, f.name));\n  }\n  if (existsSync(path.join(dest, 'test'))) for (const f of readdirSync(path.join(dest, 'test'))) sub(path.join(dest, 'test', f));\n  return dest;\n}\n\n// ── CLI flags + help ────────────────────────────────────────────────\n//\n// This file is a library first: plugins.mjs owns the user-facing `new`/`add`\n// commands and calls the exports above. But docs/SCRIPTS.md lists `node\n// plugin-install.mjs` as a runnable command, so it is reachable directly — and\n// every direct invocation printed nothing and exited 0, `--help` and a typo'd\n// flag included. That is the silent-success shape lib/cli-flags.mjs exists to","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugin-install.mjs#L107-L143","documentation":"scaffoldNew refuses to overwrite an existing plugin: if plugins.local/<name> already exists, it throws instead of clobbering your work. This is a deliberate collision guard for the destination directory.","triggerScenarios":"Calling scaffoldNew(root, name) when root/plugins.local/name exists — from a previous scaffold, a manually created folder, or a previously installed plugin with the same id.","commonSituations":"Re-running a scaffold script that already succeeded; scaffolding a plugin you previously installed from a repo; leftover directory from a failed/cancelled run; wanting to reset a plugin to template state.","solutions":["Pick a different, unique plugin name","Delete or rename the existing plugins.local/<name> directory if you truly want to start over","Inspect the existing plugin first — you may want to keep your modifications"],"exampleFix":"// before\nawait scaffoldNew(root, 'my-plugin');\n// Error: plugins.local/my-plugin already exists\n// after\nrmSync(path.join(root, 'plugins.local', 'my-plugin'), { recursive: true, force: true }); // only if reset is intended\nawait scaffoldNew(root, 'my-plugin');","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nconst dest = path.join(root, 'plugins.local', name);\nif (existsSync(dest)) throw new Error(`choose another name or remove ${dest} first`);","typeGuard":"null","tryCatchPattern":"try { await scaffoldNew(root, name); } catch (e) { if (e.message.includes('already exists')) { /* prompt user: reuse, rename, or delete */ } throw e; }","preventionTips":["Check plugins.local/ contents before scaffolding","Use idempotent scripts that skip scaffolding when the target exists","Clean up failed scaffold runs promptly"],"tags":["plugins","filesystem","collision"],"backgroundTag":"file-already-exists","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}