{"record":{"id":"79dddf031b057f03","repo":"mastra-ai/mastra","slug":"skipped-scorer-filename-already-exists-at-sc","errorCode":null,"errorMessage":"Skipped: Scorer ${filename} already exists at ${scorersPath}","messagePattern":"Skipped: Scorer (.+?) already exists at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/scorers/file-utils.ts","lineNumber":25,"sourceCode":"export function writeScorer(filename: string, content: string, customPath?: string): { ok: true; message: string } {\n  const rootDir = process.cwd();\n  const scorersPath = customPath || DEFAULT_SCORERS_DIR;\n  const fullPath = path.join(rootDir, scorersPath);\n\n  if (!fs.existsSync(fullPath)) {\n    try {\n      fs.mkdirSync(fullPath, { recursive: true });\n      p.log.success(`Created scorers directory at ${scorersPath}`);\n    } catch (error) {\n      const errorMessage = error instanceof Error ? error.message : String(error);\n      throw new Error(`Failed to create directory: ${errorMessage}`);\n    }\n  }\n\n  const filePath = path.join(fullPath, filename);\n\n  if (fs.existsSync(filePath)) {\n    throw new Error(`Skipped: Scorer ${filename} already exists at ${scorersPath}`);\n  }\n\n  try {\n    fs.writeFileSync(filePath, content);\n\n    return { ok: true, message: `Created scorer at ${path.relative(rootDir, filePath)}` };\n  } catch (error) {\n    const errorMessage = error instanceof Error ? error.message : String(error);\n    throw new Error(`Failed to write scorer: ${errorMessage}`);\n  }\n}\n","sourceCodeStart":7,"sourceCodeEnd":37,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/scorers/file-utils.ts#L7-L37","documentation":"`writeScorer` refuses to overwrite an existing scorer file. Before writing, it checks fs.existsSync on the destination and throws this 'Skipped' error to protect the user's existing code from being clobbered by a generated scorer.","triggerScenarios":"Running a scorer add/generate command where <scorersPath>/<filename> already exists on disk.","commonSituations":"Re-running a scorer generation after an earlier successful run; generating a scorer with the same name in a different session; cloning a repo that already contains the scorer file.","solutions":["Delete or rename the existing scorer file, then rerun the command","Choose a different scorer name in the command","Merge the new scorer logic manually into the existing file"],"exampleFix":"// before\nscorers/my-scorer.ts already exists\n// after\nmv scorers/my-scorer.ts scorers/my-scorer.bak.ts   # then rerun, or delete it if unwanted","handlingStrategy":"validation","validationCode":"import { existsSync, join } from 'node:fs'; // use path join\nconst target = join(scorersPath, filename);\nif (existsSync(target)) {\n  console.log('Scorer already exists, skipping or renaming first.');\n}","typeGuard":"const isAvailable = (dir: string, name: string): boolean =>\n  !existsSync(join(dir, name));","tryCatchPattern":"try {\n  await writeScorer({ ... });\n} catch (e) {\n  if ((e as Error).message.startsWith('Skipped: Scorer')) {\n    console.warn('Scorer file already exists — remove it or pick another name.');\n  } else throw e;\n}","preventionTips":["Check for existing scorer files before generating","Adopt a naming convention to avoid collisions","Use unique scorer names per feature","Clean generated scorers in CI before regeneration"],"tags":["filesystem","duplicate","cli","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}