davila7/claude-code-templates · info

Error parsing message line:

Error message

Error parsing message line:

What it means

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.

Source

Thrown at cli-tool/src/analytics.js:919

            error: 'Conversation file path not found',
            conversationId: conversationId,
            conversationKeys: Object.keys(conversation),
            hasFilePath: !!conversation.filePath,
            hasFileName: !!conversation.filename
          });
        }
        
        if (!await fs.pathExists(conversationFile)) {
          return res.status(404).json({ error: 'Conversation file not found', path: conversationFile });
        }

        const content = await fs.readFile(conversationFile, 'utf8');
        const lines = content.trim().split('\n').filter(line => line.trim());
        const rawMessages = lines.map(line => {
          try {
            return JSON.parse(line);
          } catch (error) {
            console.warn('Error parsing message line:', error);
            return null;
          }
        }).filter(Boolean);

        // Extract actual messages from Claude Code format
        const messages = rawMessages.map(item => {
          if (item.message && item.message.role) {
            let content = '';

            if (typeof item.message.content === 'string') {
              content = item.message.content;
            } else if (Array.isArray(item.message.content)) {
              content = item.message.content
                .map(block => {
                  if (block.type === 'text') return block.text;
                  if (block.type === 'tool_use') return `[Tool: ${block.name}]`;
                  if (block.type === 'tool_result') return '[Tool Result]';
                  return block.content || '';

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Close the active Claude Code session writing to that file, or exclude recently-modified files from the scan
  2. Ignore the warning — the line is skipped and analytics continue
  3. Re-validate the file with `jq -c . file.jsonl > /dev/null` to see which lines are corrupt
  4. Restore the file from backup if many lines fail
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate a conversation file cheaply
async function isValidJsonl(file) {
  const text = await fs.readFile(file, 'utf8').catch(() => null);
  return !!text && text.split('\n').filter(Boolean).every(l => { try { JSON.parse(l); return true; } catch { return false; } });
}

Try / catch

const rawMessages = lines.map(line => {
  try { return JSON.parse(line); }
  catch { return null; } // skip-and-continue is the intended pattern
}).filter(Boolean);

Prevention

When it happens

Trigger: 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.

Common situations: Scanning conversations while Claude Code is actively writing to them; crash-truncated files; files synced/edited by other tools corrupting line boundaries.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/c558cfd7f5885402. Report an issue: GitHub.