{"record":{"id":"fa431d5b340a5110","repo":"davila7/claude-code-templates","slug":"invalid-session-file-no-messages-found","errorCode":null,"errorMessage":"Invalid session file - no messages found","messagePattern":"Invalid session file - no messages found","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"cli-tool/src/session-sharing.js","lineNumber":346,"sourceCode":"   * Validate session data structure\n   * @param {Object} sessionData - Session data to validate\n   * @throws {Error} If validation fails\n   */\n  validateSessionData(sessionData) {\n    if (!sessionData.version) {\n      throw new Error('Invalid session file - missing version');\n    }\n\n    if (!sessionData.conversation || !sessionData.conversation.id) {\n      throw new Error('Invalid session file - missing conversation data');\n    }\n\n    if (!sessionData.messages || !Array.isArray(sessionData.messages)) {\n      throw new Error('Invalid session file - missing or invalid messages');\n    }\n\n    if (sessionData.messages.length === 0) {\n      throw new Error('Invalid session file - no messages found');\n    }\n  }\n\n  /**\n   * Install session in Claude Code directory structure\n   * @param {Object} sessionData - Session data to install\n   * @param {Object} options - Installation options\n   * @returns {Promise<Object>} Installation result\n   */\n  async installSession(sessionData, options = {}) {\n    const homeDir = os.homedir();\n    const claudeDir = path.join(homeDir, '.claude');\n\n    // Determine project directory\n    const projectName = sessionData.conversation.project || 'shared-session';\n    const projectDirName = this.sanitizeProjectName(projectName);\n\n    // Create project directory structure","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/session-sharing.js#L328-L364","documentation":"Thrown by validateSessionData() in cli-tool/src/session-sharing.js when the messages array exists but is empty. An export with zero messages carries no conversation content, so cloning it would create a meaningless session file; validation rejects it as the final structural check.","triggerScenarios":"Calling cloneSession()/validateSessionData() on a session that was exported before any messages were exchanged, or an export tool that writes structure (version, conversation) but strips the messages.","commonSituations":"Sharing a brand-new session with no turns yet; privacy-filtered exports that removed all messages; upstream export bug producing an empty array.","solutions":["Use a session that actually contains conversation turns","If you are the sender, verify the export includes messages before sharing","If privacy filtering stripped messages intentionally, cloning is not meaningful — skip cloneSession"],"exampleFix":"// before\nif (sessionData.messages.length === 0) {\n  throw new Error('Invalid session file - no messages found');\n}\n\n// after\nif (sessionData.messages.length === 0) {\n  throw new Error('Invalid session file - no messages found (export the session after at least one conversation turn)');\n}","handlingStrategy":"validation","validationCode":"if (data.messages.length === 0) {\n  console.warn('Session has no messages — cloning would be empty; skipping.');\n  return null;\n}","typeGuard":"function hasMessages(d) {\n  return Array.isArray(d.messages) && d.messages.length > 0;\n}","tryCatchPattern":"try {\n  await cloner.cloneSession(data);\n} catch (e) {\n  if (e.message.includes('no messages found')) {\n    return null; // benign — empty session, nothing to install\n  }\n  throw e;\n}","preventionTips":["Only share sessions that contain at least one conversation turn","Treat an empty-messages session as a warning, not a hard failure, in callers"],"tags":["validation","session-sharing","empty-data"],"backgroundTag":"schema-validation-failed","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}