{"record":{"id":"bcf0a9b3ccfddd60","repo":"FlowiseAI/Flowise","slug":"failed-to-process-binary-file-error-message-bcf0a9","errorCode":null,"errorMessage":"Failed to process binary file: ${error.message}","messagePattern":"Failed to process binary file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/S3File/S3File.ts","lineNumber":985,"sourceCode":"                    lastModified: fileInfo.lastModified,\n                    etag: fileInfo.etag,\n                    bucketName: fileInfo.bucketName,\n                    totalPages: docs.length // Total number of pages/sheets in the file\n                }\n\n                return docs.map((doc, index) => ({\n                    ...doc,\n                    metadata: {\n                        ...doc.metadata, // Keep original loader metadata (page numbers, etc.)\n                        ...s3Metadata, // Add S3 metadata\n                        pageIndex: index // Add page/sheet index\n                    }\n                }))\n            }\n\n            return []\n        } catch (error) {\n            throw new Error(`Failed to process binary file: ${error.message}`)\n        } finally {\n            // Clean up temporary file\n            if (tempFilePath && fsDefault.existsSync(tempFilePath)) {\n                try {\n                    fsDefault.unlinkSync(tempFilePath)\n                } catch (e) {\n                    console.warn(`Failed to delete temporary file: ${tempFilePath}`)\n                }\n            }\n        }\n    }\n\n    private async createTempFile(buffer: Buffer, fileName: string, mimeType: string): Promise<string> {\n        // Get appropriate file extension\n        let extension = path.extname(fileName)\n        if (!extension) {\n            const extensionMap: { [key: string]: string } = {\n                'application/pdf': '.pdf',","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/S3File/S3File.ts#L967-L1003","documentation":"Top-level catch in the S3File binary processor. Any exception thrown while instantiating a format-specific loader (PDFLoader, DocxLoader, LoadOfSheet, PowerpointLoader, CSVLoader), calling its load(), or building the metadata map is rethrown wrapped in this message. Like error 180 it preserves only `error.message`, losing the stack trace and class.","triggerScenarios":"A loader throws because the temp file is corrupt (e.g. truncated PDF), the spreadsheet has a locked structure, pdf-parse fails on an encrypted PDF, the CSV has invalid encoding, or fsDefault.existsSync/unlinkSync in finally throws before the catch completes.","commonSituations":"Corrupted uploads, password-protected Office/PDF docs, EML/HTML disguised with an Office MIME, disk-full during temp file write, or a version mismatch in the parsing library (pdf-parse, exceljs).","solutions":["Inspect `error.message` (it is propagated) and match it to the underlying loader's known failure modes.","Download the S3 object locally and open it in the native app to confirm it is valid and unencrypted.","Free disk space and verify the temp directory is writable.","Update or pin the parsing library version known to handle the file.","Add a pre-check (e.g. pdf-parse isEncrypted) before invoking the loader."],"exampleFix":"// before\n} catch (error) {\n    throw new Error(`Failed to process binary file: ${error.message}`)\n}\n\n// after\n} catch (error: any) {\n    throw new Error(`Failed to process binary file (${fileInfo.mimeType}): ${error?.message ?? error}`)\n}","handlingStrategy":"try-catch","validationCode":"import fs from 'fs'\nif (!fs.existsSync(tempFilePath)) {\n    throw new Error('Temp file missing before binary processing')\n}\n// crude magic-number check for PDF\nconst head = Buffer.alloc(4); const fd = fs.openSync(tempFilePath, 'r'); fs.readSync(fd, head, 0, 4, 0); fs.closeSync(fd)\nif (fileInfo.mimeType === 'application/pdf' && head.toString() !== '%PDF') {\n    throw new Error('File claims to be PDF but is not')\n}","typeGuard":"function isIDocumentArray(v: unknown): v is { pageContent: string; metadata: Record<string, unknown> }[] {\n    return Array.isArray(v) && v.every(d => d && typeof (d as any).pageContent === 'string')\n}","tryCatchPattern":"try {\n    return await processBinaryFile(...)\n} catch (e: any) {\n    // propagate but keep the inner message + cause\n    throw new Error(`Binary processing failed: ${e.message}`, { cause: e })\n}","preventionTips":["Pre-validate file integrity (magic bytes) before parsing.","Ensure temp directory has free disk space.","Pin parsing library versions and run smoke tests on sample files.","Surface the original error class to improve diagnosability."],"tags":["s3","document-loader","error-masking","parsing"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}