Skip to content

Commit 4e33b26

Browse files
iYassrclaude
andcommitted
Improve PDF error logging for debugging
Add detailed error capture at each step of PDF parsing: - getDocument initialization - Promise resolution - Full error serialization (message, name, stack) This will help diagnose why pdfjs is failing on some devices. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 30051ba commit 4e33b26

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

electron/services/document-parser.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,37 @@ async function parsePdf(buffer: Buffer): Promise<ParsedDocument> {
375375

376376
// Load the PDF document with worker disabled
377377
logDebug('Loading PDF document with pdfjs')
378-
const loadingTask = pdfjsLib.getDocument({
379-
data: uint8Array,
380-
useSystemFonts: true,
381-
disableFontFace: true,
382-
isEvalSupported: false,
383-
useWorkerFetch: false,
384-
})
378+
let loadingTask
379+
try {
380+
loadingTask = pdfjsLib.getDocument({
381+
data: uint8Array,
382+
useSystemFonts: true,
383+
disableFontFace: true,
384+
isEvalSupported: false,
385+
useWorkerFetch: false,
386+
verbosity: 0, // Suppress console warnings
387+
})
388+
logDebug('getDocument called, waiting for promise')
389+
} catch (initError) {
390+
logError('getDocument initialization failed', {
391+
message: initError instanceof Error ? initError.message : String(initError),
392+
stack: initError instanceof Error ? initError.stack : undefined
393+
})
394+
throw initError
395+
}
385396

386-
const pdfDoc = await loadingTask.promise
397+
let pdfDoc
398+
try {
399+
pdfDoc = await loadingTask.promise
400+
logDebug('PDF document promise resolved')
401+
} catch (loadError) {
402+
logError('PDF document promise rejected', {
403+
message: loadError instanceof Error ? loadError.message : String(loadError),
404+
name: loadError instanceof Error ? loadError.name : 'Unknown',
405+
stack: loadError instanceof Error ? loadError.stack : undefined
406+
})
407+
throw loadError
408+
}
387409
const numPages = pdfDoc.numPages
388410
logInfo('PDF document loaded', { numPages })
389411

@@ -458,7 +480,14 @@ async function parsePdf(buffer: Buffer): Promise<ParsedDocument> {
458480
}
459481
} catch (error) {
460482
// Fallback: try to extract what we can from the PDF using pdf-lib
461-
logError('PDF parsing with pdfjs failed, trying pdf-lib fallback', { error })
483+
// Capture full error details for debugging
484+
const errorDetails = {
485+
message: error instanceof Error ? error.message : String(error),
486+
name: error instanceof Error ? error.name : 'Unknown',
487+
stack: error instanceof Error ? error.stack : undefined,
488+
raw: String(error)
489+
}
490+
logError('PDF parsing with pdfjs failed, trying pdf-lib fallback', errorDetails)
462491

463492
try {
464493
logDebug('Attempting pdf-lib fallback for PDF')

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "maskr",
3-
"version": "1.3.12",
3+
"version": "1.3.13",
44
"description": "A privacy-focused desktop app for detecting and masking sensitive information in documents before sharing with AI or other parties",
55
"main": "dist-electron/main.js",
66
"type": "module",

0 commit comments

Comments
 (0)