{"record":{"id":"e4a3c6a27b414b37","repo":"mastra-ai/mastra","slug":"failed-to-write-scorer-errormessage","errorCode":null,"errorMessage":"Failed to write scorer: ${errorMessage}","messagePattern":"Failed to write scorer: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/scorers/file-utils.ts","lineNumber":34,"sourceCode":"    } 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":16,"sourceCodeEnd":37,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/scorers/file-utils.ts#L16-L37","documentation":"`writeScorer` wraps any failure from fs.writeFileSync when saving the generated scorer file. The underlying OS error (EACCES, ENOSPC, EISDIR, etc.) is embedded in the message. The directory was created successfully but the file write itself failed.","triggerScenarios":"fs.writeFileSync fails after the directory check — target path is read-only, path is actually a directory, out of space, or permission denied on the existing file.","commonSituations":"An existing scorer file is owned by root/read-only; the target filename is a directory; quota or disk-full conditions.","solutions":["Fix write permissions on the scorers directory or existing file","Check that the destination path is not a directory","Free disk space if the message includes ENOSPC","Run the command as a user with access to the project directory"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { accessSync, constants, existsSync, statSync } from 'node:fs';\nif (existsSync(target)) {\n  if (!statSync(target).isFile()) throw new Error(`${target} is not a regular file`);\n}\naccessSync(scorersPath, constants.W_OK);","typeGuard":"const writableTarget = (dir: string, name: string): boolean => {\n  try { accessSync(dir, constants.W_OK); return true; } catch { return false; }\n};","tryCatchPattern":"try {\n  await writeScorer({ ... });\n} catch (e) {\n  const msg = (e as Error).message;\n  if (msg.startsWith('Failed to write scorer')) {\n    console.error('Write failed (permissions/disk/path):', msg);\n  } else throw e;\n}","preventionTips":["Verify directory write permissions before generation","Ensure the destination filename is not a directory","Monitor disk space/quota in CI","Fix ownership of files created by other users (e.g. root)"],"tags":["filesystem","permissions","cli","write"],"backgroundTag":"file-write-permission-denied","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}