mastra-ai/mastra · error · Error
File path does not exist
Error message
File path does not exist
What it means
The FileLogger transport constructor checks existsSync(this.path) and throws 'File path does not exist' if the target log file's path is not present on disk. It does not create directories or files, so logging cannot start without a pre-existing file path.
Source
Thrown at packages/loggers/src/file/index.ts:15
import type { WriteStream } from 'node:fs';
import { createWriteStream, existsSync, readFileSync } from 'node:fs';
import { LoggerTransport } from '@mastra/core/logger';
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
export class FileTransport extends LoggerTransport {
path: string;
fileStream: WriteStream;
constructor({ path }: { path: string }) {
super({ objectMode: true });
this.path = path;
if (!existsSync(this.path)) {
console.info(this.path);
throw new Error('File path does not exist');
}
this.fileStream = createWriteStream(this.path, { flags: 'a' });
}
_transform(chunk: any, _encoding: string, callback: (error: Error | null, chunk: any) => void) {
try {
this.fileStream.write(chunk);
} catch (error) {
console.error('Error parsing log entry:', error);
}
callback(null, chunk);
}
_flush(callback: Function) {
// End the file stream when transform stream ends
this.fileStream.end(() => {
callback();View on GitHub (pinned to 75dd419e61)
Solutions
- Create the log file (and parent directories) before constructing the logger, e.g. mkdir -p and touch the file.
- Fix the path to an existing file, or resolve it absolutely with path.resolve so cwd doesn't change the target.
- In deployment config/infra, ensure the log directory exists and is writable by the process user.
Example fix
// before
const logger = new FileLogger({ path: 'logs/app.log' }); // throws if logs/app.log absent
// after
import { mkdirSync, existsSync, openSync, closeSync } from 'fs';
mkdirSync('logs', { recursive: true });
if (!existsSync('logs/app.log')) closeSync(openSync('logs/app.log', 'a'));
const logger = new FileLogger({ path: 'logs/app.log' }); Defensive patterns
Strategy: validation
Validate before calling
import { existsSync, mkdirSync, openSync, closeSync } from 'fs';
import path from 'path';
function ensureLogFile(p) {
mkdirSync(path.dirname(p), { recursive: true });
if (!existsSync(p)) closeSync(openSync(p, 'a'));
return p;
} Try / catch
try {
const logger = new FileLogger({ path: logPath });
} catch (e) {
if (e.message === 'File path does not exist') {
console.error(`Log file missing: ${logPath}; create it or fix the path`);
}
throw e;
} Prevention
- Create the log file (touch) and its directories during app bootstrap.
- Use absolute paths (path.resolve) so relative paths don't break with different cwd.
- In containers/deploys, provision the log directory as part of setup.
When it happens
Trigger: new FileLogger({ path: '...' }) where path points to a nonexistent file or an unwritable/missing directory.
Common situations: Deployments where the log directory isn't provisioned; typos in path; relative path resolved against unexpected cwd; container with different filesystem layout; expecting the logger to create the file (it won't).
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Missing required query param: ${label}
- ${label} must be relative
- ${label} escapes workspace
- Path escapes workspace
- Path is a directory
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/fae4acd200b7840b.
Report an issue: GitHub.