mastra-ai/mastra · error
Failed to write scorer
Error message
Failed to write scorer: ${errorMessage} What it means
`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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
import { accessSync, constants, existsSync, statSync } from 'node:fs';
if (existsSync(target)) {
if (!statSync(target).isFile()) throw new Error(`${target} is not a regular file`);
}
accessSync(scorersPath, constants.W_OK); Type guard
const writableTarget = (dir: string, name: string): boolean => {
try { accessSync(dir, constants.W_OK); return true; } catch { return false; }
}; Try / catch
try {
await writeScorer({ ... });
} catch (e) {
const msg = (e as Error).message;
if (msg.startsWith('Failed to write scorer')) {
console.error('Write failed (permissions/disk/path):', msg);
} else throw e;
} Prevention
- 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)
When it happens
Trigger: 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.
Common situations: An existing scorer file is owned by root/read-only; the target filename is a directory; quota or disk-full conditions.
Understand the failure class
Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.
Related errors
- Failed to create directory
- A file or directory named
- Could not read file
- Directory not found: .
- Directory already exists
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/e4a3c6a27b414b37.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/commands/scorers/file-utils.ts:34
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to create directory: ${errorMessage}`);
}
}
const filePath = path.join(fullPath, filename);
if (fs.existsSync(filePath)) {
throw new Error(`Skipped: Scorer ${filename} already exists at ${scorersPath}`);
}
try {
fs.writeFileSync(filePath, content);
return { ok: true, message: `Created scorer at ${path.relative(rootDir, filePath)}` };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to write scorer: ${errorMessage}`);
}
}
View on GitHub (pinned to 75dd419e61)