thedotmack/claude-mem · warning

Failed to parse transcript line (non-Error thrown)

Error message

Failed to parse transcript line (non-Error thrown)

What it means

handleLine wraps transcript-line parsing in a try/catch; when the thrown value is not an Error instance (e.g. a string or object was thrown), it logs a warn instead of a debug and stringifies the thrown value. Parsing of that line is aborted but the watcher keeps running.

Solutions

  1. Inspect the `error` field (String(error)) to identify the malformed line and the underlying message.
  2. Fix or remove the corrupted transcript line/file that triggers the parse failure.
  3. Upgrade claude-mem — parsers throwing non-Errors is usually fixed upstream.
  4. If caused by a third-party parser dependency, pin/upgrade that dependency so it throws proper Errors.

Example fix

// before (third-party parser)
throw 'bad line'
// after
throw new Error('bad line')
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof line !== 'string' || line.trim() === '') return;
try { JSON.parse(line); } catch { console.warn('Non-JSONL line in transcript'); }

Type guard

function isError(e: unknown): e is Error {
  return e instanceof Error;
}

Try / catch

try {
  parseTranscriptLine(line);
} catch (error) {
  const detail = error instanceof Error ? error.stack : String(error);
  logger.warn('parse failed', { detail });
}

Prevention

When it happens

Trigger: tailer -> handleLine on a transcript line whose parser throws a non-Error value — malformed/foreign JSONL content, a parser library that throws strings, or third-party code throwing plain objects.

Common situations: Corrupted or hand-edited transcript JSONL files; logs written by another tool that claude-mem's parser chokes on; a parser bug that throws `throw 'unexpected token'`.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/8644594b1af14e42. Report an issue: GitHub.

Appendix: source

Thrown at src/services/transcripts/watcher.ts:315

  private async handleLine(
    line: string,
    watch: WatchTarget,
    schema: TranscriptSchema,
    filePath: string,
    sessionIdOverride?: string | null
  ): Promise<void> {
    try {
      const entry = JSON.parse(line);
      await this.processor.processEntry(entry, watch, schema, sessionIdOverride ?? undefined);
    } catch (error: unknown) {
      if (error instanceof Error) {
        logger.debug('TRANSCRIPT', 'Failed to parse transcript line', {
          watch: watch.name,
          file: basename(filePath)
        }, error);
      } else {
        logger.warn('TRANSCRIPT', 'Failed to parse transcript line (non-Error thrown)', {
          watch: watch.name,
          file: basename(filePath),
          error: String(error)
        });
      }
    }
  }

  private extractSessionIdFromPath(filePath: string): string | null {
    const match = filePath.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i);
    return match ? match[0] : null;
  }
}

View on GitHub (pinned to d8bc9755e7)