{"record":{"id":"c558cfd7f5885402","repo":"davila7/claude-code-templates","slug":"error-parsing-message-line","errorCode":null,"errorMessage":"Error parsing message line:","messagePattern":"Error parsing message line:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"cli-tool/src/analytics.js","lineNumber":919,"sourceCode":"            error: 'Conversation file path not found',\n            conversationId: conversationId,\n            conversationKeys: Object.keys(conversation),\n            hasFilePath: !!conversation.filePath,\n            hasFileName: !!conversation.filename\n          });\n        }\n        \n        if (!await fs.pathExists(conversationFile)) {\n          return res.status(404).json({ error: 'Conversation file not found', path: conversationFile });\n        }\n\n        const content = await fs.readFile(conversationFile, 'utf8');\n        const lines = content.trim().split('\\n').filter(line => line.trim());\n        const rawMessages = lines.map(line => {\n          try {\n            return JSON.parse(line);\n          } catch (error) {\n            console.warn('Error parsing message line:', error);\n            return null;\n          }\n        }).filter(Boolean);\n\n        // Extract actual messages from Claude Code format\n        const messages = rawMessages.map(item => {\n          if (item.message && item.message.role) {\n            let content = '';\n\n            if (typeof item.message.content === 'string') {\n              content = item.message.content;\n            } else if (Array.isArray(item.message.content)) {\n              content = item.message.content\n                .map(block => {\n                  if (block.type === 'text') return block.text;\n                  if (block.type === 'tool_use') return `[Tool: ${block.name}]`;\n                  if (block.type === 'tool_result') return '[Tool Result]';\n                  return block.content || '';","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics.js#L901-L937","documentation":"A per-line warning while parsing a Claude Code conversation .jsonl file: one line failed JSON.parse, so it's skipped (mapped to null and filtered out). Non-fatal by design; malformed/truncated lines are dropped.","triggerScenarios":"A partially-written last line in a .jsonl conversation file (Claude Code still writing), embedded NUL bytes, or an empty/truncated line that survived the filter. Fires for each bad line during message loading.","commonSituations":"Scanning conversations while Claude Code is actively writing to them; crash-truncated files; files synced/edited by other tools corrupting line boundaries.","solutions":["Close the active Claude Code session writing to that file, or exclude recently-modified files from the scan","Ignore the warning — the line is skipped and analytics continue","Re-validate the file with `jq -c . file.jsonl > /dev/null` to see which lines are corrupt","Restore the file from backup if many lines fail"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate a conversation file cheaply\nasync function isValidJsonl(file) {\n  const text = await fs.readFile(file, 'utf8').catch(() => null);\n  return !!text && text.split('\\n').filter(Boolean).every(l => { try { JSON.parse(l); return true; } catch { return false; } });\n}","typeGuard":null,"tryCatchPattern":"const rawMessages = lines.map(line => {\n  try { return JSON.parse(line); }\n  catch { return null; } // skip-and-continue is the intended pattern\n}).filter(Boolean);","preventionTips":["Exclude files modified in the last few seconds from scans (still being written)","Never assume every .jsonl line parses — always null-filter","Keep backups of ~/.claude/projects if analytics fidelity matters"],"tags":["jsonl","parsing","analytics","skip-line"],"backgroundTag":"jsonl-partial-line-parse-error","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}