mastra-ai/mastra · error

Failed to write scorer: ${errorMessage}

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.

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)

Solutions

  1. Fix write permissions on the scorers directory or existing file
  2. Check that the destination path is not a directory
  3. Free disk space if the message includes ENOSPC
  4. 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

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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/e4a3c6a27b414b37. Report an issue: GitHub.