{"record":{"id":"ed4bf2c2cb4699b1","repo":"davila7/claude-code-templates","slug":"invalid-session-file-missing-version","errorCode":null,"errorMessage":"Invalid session file - missing version","messagePattern":"Invalid session file - missing version","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli-tool/src/session-sharing.js","lineNumber":334,"sourceCode":"      // Parse JSON response\n      const sessionData = JSON.parse(stdout);\n      return sessionData;\n    } catch (error) {\n      if (error.message.includes('Unexpected token')) {\n        throw new Error('Invalid session file - corrupted or not a Claude Code session');\n      }\n      throw error;\n    }\n  }\n\n  /**\n   * 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","sourceCodeStart":316,"sourceCodeEnd":352,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/session-sharing.js#L316-L352","documentation":"Thrown by validateSessionData() in cli-tool/src/session-sharing.js when the parsed session object lacks a top-level 'version' field. Every Claude Code session export must carry a version identifying its schema; its absence means the JSON is valid but is not a session export (or is an unversioned/corrupted one).","triggerScenarios":"Calling cloneSession()/validateSessionData() on JSON that parses fine but has no 'version' key — e.g. downloading the wrong file, a hand-edited export, or a JSON error payload from the hosting service.","commonSituations":"Pointing downloadSession at an arbitrary JSON file instead of a session export; session exports produced by incompatible/older tooling that omitted the version field; keys stripped by manual editing.","solutions":["Inspect the downloaded JSON (Object.keys) and confirm it looks like a session export with version/conversation/messages","Re-share the session with the current CLI version so the export includes 'version'","Verify you are downloading the exact URL returned by uploadToX0, not a directory listing or other file"],"exampleFix":"// before\nif (!sessionData.version) {\n  throw new Error('Invalid session file - missing version');\n}\n\n// after\nif (!sessionData.version) {\n  throw new Error(`Invalid session file - missing version (keys found: ${Object.keys(sessionData).join(', ')})`);\n}","handlingStrategy":"type-guard","validationCode":"const data = JSON.parse(raw);\nif (!('version' in data)) {\n  throw new Error('Not a session export: missing version field');\n}","typeGuard":"function isSessionExport(d) {\n  return Boolean(d) && typeof d === 'object'\n    && typeof d.version !== 'undefined'\n    && d.conversation && typeof d.conversation.id === 'string'\n    && Array.isArray(d.messages);\n}","tryCatchPattern":"try {\n  cloner.cloneSession(data);\n} catch (e) {\n  if (/Invalid session file/.test(e.message)) {\n    console.error('The downloaded file is not a valid session export:', e.message);\n    return; // recoverable: ask user for a correct link\n  }\n  throw e;\n}","preventionTips":["Run a single isSessionExport() guard covering all four structural checks before calling cloneSession","Always download from URLs produced by the same tool version that will consume them"],"tags":["validation","session-sharing","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}