{"record":{"id":"7d3d89e837c2b381","repo":"davila7/claude-code-templates","slug":"could-not-generate-qr-code","errorCode":null,"errorMessage":"⚠️  Could not generate QR code:","messagePattern":"⚠️  Could not generate QR code:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-tool/src/session-sharing.js","lineNumber":435,"sourceCode":"    try {\n      // Generate QR code as Data URL (for web display)\n      const qrDataUrl = await QRCode.toDataURL(command, {\n        errorCorrectionLevel: 'M',\n        type: 'image/png',\n        width: 300,\n        margin: 2,\n        color: {\n          dark: '#000000',\n          light: '#FFFFFF'\n        }\n      });\n\n      return {\n        dataUrl: qrDataUrl,\n        command: command\n      };\n    } catch (error) {\n      console.warn(chalk.yellow('⚠️  Could not generate QR code:'), error.message);\n      return {\n        dataUrl: null,\n        command: command\n      };\n    }\n  }\n\n  /**\n   * Sanitize project name for directory usage\n   * @param {string} projectName - Original project name\n   * @returns {string} Sanitized name\n   */\n  sanitizeProjectName(projectName) {\n    // Replace spaces and special chars with hyphens\n    return projectName\n      .replace(/[^a-zA-Z0-9-_]/g, '-')\n      .replace(/-+/g, '-')\n      .toLowerCase();","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/session-sharing.js#L417-L453","documentation":"generateQRCode builds a shareable session QR (rendering the session command to a data-URL image) and warns when QR generation fails, returning { dataUrl: null, command }. The command is still usable, so this degrades to a text-only sharing experience. Failure almost always comes from the underlying qrcode library (invalid input text, unsupported payload) or an encoding/render error.","triggerScenarios":"Calling generateQRCode when the command string to encode is empty or too long for a QR code, when the qrcode dependency is missing or an incompatible version, or when toDataURL options are misconfigured (bad errorCorrectionLevel/format).","commonSituations":"Session token or command string grew beyond QR capacity (~2-3KB); qrcode package not installed after a partial npm install; running in an environment where the QR renderer's optional native deps are unavailable.","solutions":["Verify the `qrcode` package is installed and importable (`node -e \"require('qrcode')\"`)","Shorten the encoded payload (share a URL/short code instead of the full command) and re-run","Pin or upgrade qrcode to a known-good version (`npm i qrcode@^1.5.x`)","Fall back to the returned `command` string — copy/paste sharing still works without the QR"],"exampleFix":"// before\nconst qr = await generateQRCode(veryLongCommand);\n// after\nconst qr = await generateQRCode(command);\nif (!qr.dataUrl) {\n  console.log('Copy this command instead:', qr.command);\n}","handlingStrategy":"fallback","validationCode":"if (typeof command !== 'string' || command.length === 0 || command.length > 2000) {\n  // skip QR, use text-only sharing\n  return { dataUrl: null, command };\n}","typeGuard":null,"tryCatchPattern":"catch (error) {\n  return { dataUrl: null, command }; // always fall back to the plain command\n}","preventionTips":["Keep the encoded payload short (short codes/URLs, not full tokens)","Lock the qrcode dependency version in package.json","Always render a copyable command alongside the QR so sharing works without it"],"tags":["qrcode","session-sharing","graceful-degradation"],"backgroundTag":"qrcode-generation-failed","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}