{"record":{"id":"fae4acd200b7840b","repo":"mastra-ai/mastra","slug":"file-path-does-not-exist","errorCode":null,"errorMessage":"File path does not exist","messagePattern":"File path does not exist","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/loggers/src/file/index.ts","lineNumber":15,"sourceCode":"import type { WriteStream } from 'node:fs';\nimport { createWriteStream, existsSync, readFileSync } from 'node:fs';\nimport { LoggerTransport } from '@mastra/core/logger';\nimport type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\n\nexport class FileTransport extends LoggerTransport {\n  path: string;\n  fileStream: WriteStream;\n  constructor({ path }: { path: string }) {\n    super({ objectMode: true });\n    this.path = path;\n\n    if (!existsSync(this.path)) {\n      console.info(this.path);\n      throw new Error('File path does not exist');\n    }\n\n    this.fileStream = createWriteStream(this.path, { flags: 'a' });\n  }\n\n  _transform(chunk: any, _encoding: string, callback: (error: Error | null, chunk: any) => void) {\n    try {\n      this.fileStream.write(chunk);\n    } catch (error) {\n      console.error('Error parsing log entry:', error);\n    }\n    callback(null, chunk);\n  }\n\n  _flush(callback: Function) {\n    // End the file stream when transform stream ends\n    this.fileStream.end(() => {\n      callback();","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/loggers/src/file/index.ts#L1-L33","documentation":"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.","triggerScenarios":"new FileLogger({ path: '...' }) where path points to a nonexistent file or an unwritable/missing directory.","commonSituations":"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).","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."],"exampleFix":"// before\nconst logger = new FileLogger({ path: 'logs/app.log' }); // throws if logs/app.log absent\n// after\nimport { mkdirSync, existsSync, openSync, closeSync } from 'fs';\nmkdirSync('logs', { recursive: true });\nif (!existsSync('logs/app.log')) closeSync(openSync('logs/app.log', 'a'));\nconst logger = new FileLogger({ path: 'logs/app.log' });","handlingStrategy":"validation","validationCode":"import { existsSync, mkdirSync, openSync, closeSync } from 'fs';\nimport path from 'path';\nfunction ensureLogFile(p) {\n  mkdirSync(path.dirname(p), { recursive: true });\n  if (!existsSync(p)) closeSync(openSync(p, 'a'));\n  return p;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const logger = new FileLogger({ path: logPath });\n} catch (e) {\n  if (e.message === 'File path does not exist') {\n    console.error(`Log file missing: ${logPath}; create it or fix the path`);\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["filesystem","logging","validation"],"backgroundTag":"file-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}