chatboxai/chatbox · error · Error

20029

20029

Error message

local_parser_failed

What it means

Thrown by parsePdfFileLocally() when isPdfFilePath(file.name) is false — i.e. the file extension is not recognized as PDF. It is an early guard before any pdfjs work is done. The sentinel string 'local_parser_failed' (code 20029) is a stable handle callers match on to route the user toward a server-side/alternative parser.

Source

Thrown at src/renderer/packages/pdf-parser.ts:38

function isPdfTextItem(item: unknown): item is PdfTextItem {
  return (
    typeof item === 'object' &&
    item !== null &&
    'str' in item &&
    typeof (item as PdfTextItem).str === 'string' &&
    Array.isArray((item as PdfTextItem).transform)
  )
}

async function loadPdfjs() {
  const pdfjs = await import('pdfjs-dist/legacy/build/pdf.mjs')
  pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl
  return pdfjs
}

export async function parsePdfFileLocally(file: File): Promise<string> {
  if (!isPdfFilePath(file.name)) {
    throw new Error('local_parser_failed')
  }

  if (file.size > LOCAL_PARSER_MAX_PDF_FILE_SIZE) {
    throw new Error(LOCAL_PARSER_FILE_TOO_LARGE_ERROR)
  }

  const { getDocument } = await loadPdfjs()
  const loadingTask = getDocument({
    data: new Uint8Array(await file.arrayBuffer()),
    useSystemFonts: true,
  })

  try {
    const document = await loadingTask.promise
    const pageTexts: string[] = []

    for (let pageNumber = 1; pageNumber <= document.numPages; pageNumber++) {
      try {

View on GitHub (pinned to 81571269ad)

Solutions

  1. Ensure the file genuinely is a PDF and has a .pdf extension before this call.
  2. Route non-PDF files to their correct parser instead of the PDF path.
  3. If the file is a PDF with a missing extension, rename it or fix the upstream dispatcher to use content-type, not extension.
Defensive patterns

Strategy: validation

Validate before calling

if (!isPdfFilePath(file.name)) {
  // route to the correct parser; do not call parsePdfFileLocally
}

Type guard

function looksLikePdf(file: File): boolean {
  return file.type === 'application/pdf' || isPdfFilePath(file.name)
}

Try / catch

try {
  await parsePdfFileLocally(file)
} catch (e) {
  if (e instanceof Error && e.message === 'local_parser_failed') {
    // offer alternative parser or reject the attachment
  }
}

Prevention

When it happens

Trigger: Calling parsePdfFileLocally() with a File whose name lacks a .pdf extension (or whatever isPdfFilePath accepts). The check `if (!isPdfFilePath(file.name)) throw new Error('local_parser_failed')` fires immediately.

Common situations: File picker/attachment pipeline routes a non-PDF file into the PDF parser path; file renamed without .pdf extension but is actually a PDF; a content-type vs filename mismatch where the dispatcher used the wrong parser by extension.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/95691ef5f696e678. Report an issue: GitHub.