{"record":{"id":"9ffc36d48c919438","repo":"davila7/claude-code-templates","slug":"download-failed-stderr","errorCode":null,"errorMessage":"Download failed: ${stderr}","messagePattern":"Download failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli-tool/src/session-sharing.js","lineNumber":313,"sourceCode":"      console.error(chalk.red('❌ Failed to clone session:'), error.message);\n      throw error;\n    }\n  }\n\n  /**\n   * Download session data from URL\n   * @param {string} url - URL to download from\n   * @returns {Promise<Object>} Session data\n   */\n  async downloadSession(url) {\n    try {\n      // Use curl to download (works with x0.at and other services)\n      const { stdout, stderr } = await execAsync(`curl -L \"${url}\"`, {\n        maxBuffer: 50 * 1024 * 1024 // 50MB buffer for large sessions\n      });\n\n      if (stderr && !stdout) {\n        throw new Error(`Download failed: ${stderr}`);\n      }\n\n      // 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   */","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/session-sharing.js#L295-L331","documentation":"Thrown by downloadSession() in cli-tool/src/session-sharing.js when curl was used to fetch a shared session URL and produced stderr output with no stdout. This means the download itself failed at the transport level (DNS failure, TLS error, 404, connection refused) rather than returning corrupt data. The curl stderr text is embedded in the message.","triggerScenarios":"Calling downloadSession(url)/sessionData with a URL that no longer exists (x0.at files expire after 3-100 days), a mistyped URL, no network connectivity, or a TLS-intercepting proxy that breaks the connection.","commonSituations":"Trying to clone a session whose x0.at link has expired; air-gapped or proxy-filtered environments where curl cannot resolve or reach the host; URL copied with trailing characters or quotes.","solutions":["Verify the URL opens in a browser — x0.at deletes files after 3-100 days, so expired links are the most common cause","Test connectivity: curl -L \"<url>\" and read the stderr/code","If behind a proxy, ensure HTTPS_PROXY/https_proxy env vars are set so curl can traverse it","Ask the sender to re-upload the session if the link has expired"],"exampleFix":"// before\nconst { stdout, stderr } = await execAsync(`curl -L \"${url}\"`);\nif (stderr && !stdout) {\n  throw new Error(`Download failed: ${stderr}`);\n}\n\n// after\nconst { stdout, stderr } = await execAsync(`curl -fL --retry 2 \"${url}\"`);\nif (stderr && !stdout) {\n  throw new Error(`Download failed for ${url}: ${stderr}`);\n}","handlingStrategy":"retry","validationCode":"// Pre-check the URL is alive before downloading\nconst { stdout } = await execAsync(`curl -sIL -o /dev/null -w '%{http_code}' \"${url}\"`);\nif (stdout.trim() !== '200') throw new Error(`Link not downloadable (HTTP ${stdout.trim()}) — possibly expired`);","typeGuard":null,"tryCatchPattern":"try {\n  const data = await downloader.downloadSession(url);\n} catch (e) {\n  if (/^Download failed/.test(e.message)) {\n    // expired link or network issue — tell user and stop, no point parsing\n    throw new Error(`Session link unavailable: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["Use curl's -f/--fail flags so HTTP errors surface as failures","Re-share sessions before x0.at's 3-100 day expiry","Store the share date alongside the URL so consumers can judge freshness"],"tags":["network","download","curl","session-sharing","expired-url"],"backgroundTag":"download-failed","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}