{"record":{"id":"33c7822d77cd04b1","repo":"google-gemini/gemini-cli","slug":"enoent","errorCode":"ENOENT","errorMessage":"Sandbox Error: read_file failed for '${filePath}'. Exit code ${code}. ${error ? 'Details: ' + error : ''}","messagePattern":"Sandbox Error: read_file failed for '(.+?)'\\. Exit code (.+?)\\. (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/sandboxedFileSystemService.ts","lineNumber":95,"sourceCode":"\n        child.stderr?.on('data', (data) => {\n          error += data.toString();\n        });\n\n        child.on('close', (code) => {\n          if (code === 0) {\n            resolve(output);\n          } else {\n            const isEnoent =\n              error.toLowerCase().includes('no such file or directory') ||\n              error.toLowerCase().includes('enoent') ||\n              error.toLowerCase().includes('could not find file') ||\n              error.toLowerCase().includes('could not find a part of the path');\n            const err = new Error(\n              `Sandbox Error: read_file failed for '${filePath}'. Exit code ${code}. ${error ? 'Details: ' + error : ''}`,\n            );\n            if (isEnoent) {\n              Object.assign(err, { code: 'ENOENT' });\n            }\n            reject(err);\n          }\n        });\n\n        child.on('error', (err) => {\n          reject(\n            new Error(\n              `Sandbox Error: Failed to spawn read_file for '${filePath}': ${err.message}`,\n            ),\n          );\n        });\n      });\n    } finally {\n      prepared.cleanup?.();\n    }\n  }\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/services/sandboxedFileSystemService.ts#L77-L113","documentation":"ENOENT 'Sandbox Error: read_file failed for X' is thrown by SandboxedFileSystemService.readTextFile when the sandboxed __read child process exits non-zero AND its stderr matches an ENOENT-like phrase. The wrapper attaches code:'ENOENT' so callers can distinguish missing-file from permission/spawn failures.","triggerScenarios":"readTextFile(filePath) -> sanitizeAndValidatePath OK -> spawn __read -> child exits non-zero -> stderr contains 'no such file or directory' | 'enoent' | 'could not find file' | 'could not find a part of the path' -> reject(err with code ENOENT).","commonSituations":"write-file/edit tool targets a file the model assumed existed; path was mapped to a sandbox root that does not contain the file; file was deleted between the tool listing and the read; Windows sandbox reporting 'could not find a part of the path'.","solutions":["Existence-check before read (config.getFileSystemService().readTextFile inside an ENOENT catch, or fs.stat).","Verify the path is inside the sandbox cwd and allowedPaths — sandbox path remapping can resolve to a different root.","If the file should exist, re-run the tool that was supposed to create it."],"exampleFix":"// before\nconst txt = await fs.readTextFile(p);\n// after\ntry { const txt = await fs.readTextFile(p); }\ncatch (e) { if (isNodeError(e) && e.code === 'ENOENT') { /* create or skip */ } else throw e; }","handlingStrategy":"try-catch","validationCode":"// existence-check via the same FS service to respect sandbox mapping\nconst exists = await config.getFileSystemService().exists(filePath);\nif (!exists) return { fileExists: false };","typeGuard":"function isSandboxEnoent(e: unknown): boolean {\n  return isNodeError(e) && (e as NodeJS.ErrnoException).code === 'ENOENT';\n}","tryCatchPattern":"try { return await fs.readTextFile(p); }\ncatch (e) {\n  if (isSandboxEnoent(e)) { /* treat as new file */ return ''; }\n  throw e;\n}","preventionTips":["Use the same sandboxed FS service for stat and read so path mapping is consistent.","Validate the path is under the sandbox cwd + allowedPaths before reading."],"tags":["sandbox","filesystem","enoent","typescript"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}