{"record":{"id":"d81df96c2dcee566","repo":"Stirling-Tools/Stirling-PDF","slug":"file-file-name-appears-to-be-corrupted","errorCode":null,"errorMessage":"File ${file.name} appears to be corrupted","messagePattern":"File (.+?) appears to be corrupted","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/core/services/enhancedPDFProcessingService.ts","lineNumber":74,"sourceCode":"  ): Promise<ProcessedFile | null> {\n    const fileKey = await this.generateFileKey(file);\n\n    // Check cache first\n    const cached = this.cache.get(fileKey);\n    if (cached) {\n      this.updateMetrics(\"cacheHit\");\n      return cached;\n    }\n\n    // Check if already processing\n    if (this.processing.has(fileKey)) {\n      return null;\n    }\n\n    // Analyze file to determine optimal strategy\n    const analysis = await FileAnalyzer.analyzeFile(file);\n    if (analysis.isCorrupted) {\n      throw new Error(`File ${file.name} appears to be corrupted`);\n    }\n\n    // Create processing config\n    const config: ProcessingConfig = {\n      ...this.defaultConfig,\n      strategy: analysis.recommendedStrategy,\n      ...customConfig,\n    };\n\n    // Start processing\n    this.startProcessing(\n      file,\n      fileKey,\n      config,\n      analysis.estimatedProcessingTime,\n    );\n    return null;\n  }","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/core/services/enhancedPDFProcessingService.ts#L56-L92","documentation":"`processFile` calls `FileAnalyzer.analyzeFile`, which runs pdf.js (`quickPDFAnalysis`) and flags `isCorrupted=true` whenever pdf.js throws an error that does NOT contain 'password'/'encrypted'. So 'corrupted' really means 'pdf.js could not parse this file for any non-encryption reason' — it is a catch-all, not a true structural-corruption check.","triggerScenarios":"Uploading a non-PDF file renamed to `.pdf`; a truncated or half-downloaded PDF; a PDF with a broken xref/trailer; a file the pdf.js worker failed to fetch into (worker crashed/timed out); zero-byte file. Also fires if the pdf.js worker itself is misconfigured and `createDocument` rejects for unrelated reasons.","commonSituations":"User renames an image/doc to `.pdf`; download interrupted leaving a partial file; older pdf.js worker version choking on a valid newer-PDF feature (e.g. PDF 2.0); the Web Worker that hosts pdf.js failed to spawn so every file 'fails to parse'.","solutions":["Before `processFile`, call `FileAnalyzer.isValidPDF(file)` (checks `%PDF-` header) to reject obvious non-PDFs with a clear message.","Distinguish 'worker unavailable' from 'corrupt file': if `pdfWorkerManager` failed to initialise, treat that as a service error, not corruption.","Offer the user a repair/re-upload path and surface the original pdf.js error message (currently swallowed) so the cause is diagnosable.","If the file is large, confirm it isn't merely a slow parse — the analyzer parses synchronously and a timeout looks identical to corruption."],"exampleFix":"// before\nconst analysis = await FileAnalyzer.analyzeFile(file);\nif (analysis.isCorrupted) {\n  throw new Error(`File ${file.name} appears to be corrupted`);\n}\n\n// after (cheap header check + richer cause)\nconst analysis = await FileAnalyzer.analyzeFile(file);\nif (analysis.isCorrupted) {\n  const validHeader = await FileAnalyzer.isValidPDF(file);\n  throw new Error(\n    validHeader\n      ? `File ${file.name} could not be parsed (may be damaged or use an unsupported feature)`\n      : `File ${file.name} is not a valid PDF`,\n  );\n}","handlingStrategy":"validation","validationCode":"// Reject obvious non-PDFs before the heavy analyze step\nconst isValid = await FileAnalyzer.isValidPDF(file);\nif (!isValid) {\n  notifyUser(`${file.name} is not a valid PDF`);\n  return;\n}","typeGuard":"function isLikelyPdf(file: File): boolean {\n  return file.type === \"application/pdf\" || file.name.toLowerCase().endsWith(\".pdf\");\n}","tryCatchPattern":"try {\n  const result = await service.processFile(file);\n} catch (e) {\n  const msg = e instanceof Error ? e.message : \"\";\n  if (msg.includes(\"appears to be corrupted\")) {\n    notifyUser(`${file.name} could not be parsed. It may be damaged or in an unsupported format.`);\n  } else { throw e; }\n}","preventionTips":["Run `FileAnalyzer.isValidPDF` (header check) before `processFile` to reject non-PDFs cheaply.","Distinguish a dead pdf.js worker from genuine corruption before labelling a file corrupt.","Surface the underlying pdf.js error message so users can diagnose truncation vs unsupported features.","Confirm large files aren't just slow to parse (a timeout reads identically to corruption)."],"tags":["pdf","validation","file-analysis","pdfjs","corruption"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}