{"record":{"id":"9d0267c58bd1b16d","repo":"google-gemini/gemini-cli","slug":"failed-to-find-session-trimmedresumearg-er","errorCode":null,"errorMessage":"Failed to find session \"${trimmedResumeArg}\": ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to find session \"(.+?)\": (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/sessionUtils.ts","lineNumber":527,"sourceCode":"      }\n\n      // Sort by startTime (oldest first, so newest sessions get highest numbers)\n      sessions.sort(\n        (a, b) =>\n          new Date(a.startTime).getTime() - new Date(b.startTime).getTime(),\n      );\n\n      selectedSession = sessions[sessions.length - 1];\n    } else {\n      try {\n        selectedSession = await this.findSession(trimmedResumeArg);\n      } catch (error) {\n        // SessionError already has detailed messages - just rethrow\n        if (error instanceof SessionError) {\n          throw error;\n        }\n        // Wrap unexpected errors with context\n        throw new Error(\n          `Failed to find session \"${trimmedResumeArg}\": ${error instanceof Error ? error.message : String(error)}`,\n        );\n      }\n    }\n\n    return this.selectSession(selectedSession);\n  }\n\n  /**\n   * Loads session data for a selected session.\n   */\n  private async selectSession(\n    sessionInfo: SessionInfo,\n  ): Promise<SessionSelectionResult> {\n    const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');\n    const sessionPath = path.join(chatsDir, sessionInfo.fileName);\n\n    try {","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/utils/sessionUtils.ts#L509-L545","documentation":"Thrown when resuming a session by identifier and this.findSession(trimmedResumeArg) throws an error that is NOT a SessionError (those are rethrown unchanged). It wraps unexpected/low-level errors (filesystem, JSON parse, permission) with the identifier that was requested for diagnosis.","triggerScenarios":"findSession throws something other than SessionError — e.g. an FS error reading the chats directory, an unexpected JSON.parse failure, or a permission error. The wrapper at sessionUtils.ts:527 catches and rethrows with context.","commonSituations":"Chats directory is corrupted or has permission issues. Disk error while listing session files. A bug in findSession producing a non-SessionError. Race where the session file is deleted between listing and reading.","solutions":["Read the wrapped error message (after the colon) to identify the underlying cause (ENOENT, EACCES, SyntaxError).","Verify the chats directory (storage.getProjectTempDir()/chats) is readable and not corrupted.","If a specific session file is corrupt, remove or restore it, then retry the resume.","If the identifier is wrong, double-check it against the session list (`--list-sessions` or equivalent)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate the identifier format and chats dir accessibility before resuming.\nconst fs = require('fs');\nconst chatsDir = path.join(storage.getProjectTempDir(), 'chats');\nfs.accessSync(chatsDir, fs.constants.R_OK);","typeGuard":null,"tryCatchPattern":"try {\n  selectedSession = await manager.findSession(id);\n} catch (e) {\n  if (e instanceof SessionError) throw e; // already detailed\n  throw new Error(`Failed to find session '${id}': ${e.message}`);\n}","preventionTips":["Ensure the chats directory is readable before listing sessions.","Treat SessionError distinctly from wrapped errors in your handler."],"tags":["session","resume","filesystem","error-wrapping"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}