Skip to content

Commit e504128

Browse files
authored
🫙 fix: Surface Document Extraction Failures (#15651)
Co-authored-by: aeyeopsdev <275853971+aeyeopsdev@users.noreply.github.com>
1 parent 6cd6be6 commit e504128

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

api/server/services/Files/process.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ const processAgentFileUpload = async ({ req, res, metadata, sseStream }) => {
889889
`[processAgentFileUpload] Document parser failed for ${extractionFileLabel}:`,
890890
errorMetadata,
891891
);
892+
throw err;
892893
}
893894
};
894895

api/server/services/Files/process.spec.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ describe('processAgentFileUpload', () => {
622622

623623
await expect(
624624
processAgentFileUpload({ req, res: mockRes, metadata: makeMetadata() }),
625-
).rejects.toThrow(/image-based and requires an OCR service/);
625+
).rejects.toThrow('No text found in document');
626626

627627
expect(parseText).not.toHaveBeenCalled();
628628
});
@@ -632,8 +632,11 @@ describe('processAgentFileUpload', () => {
632632
handleFileUpload: jest.fn().mockRejectedValue(new Error('PRIVATE parser failure')),
633633
});
634634
extractInspectableFileText.mockImplementationOnce(async ({ extract }) => {
635-
await extract();
636-
throw makeUninspectableExtractedTextError();
635+
try {
636+
await extract();
637+
} catch {
638+
throw makeUninspectableExtractedTextError();
639+
}
637640
});
638641
const req = makeReq({
639642
mimetype: PDF_MIME,
@@ -771,7 +774,7 @@ describe('processAgentFileUpload', () => {
771774

772775
await expect(
773776
processAgentFileUpload({ req, res: mockRes, metadata: makeMetadata() }),
774-
).rejects.toThrow(/image-based and requires an OCR service/);
777+
).rejects.toThrow('failure');
775778

776779
expect(parseText).not.toHaveBeenCalled();
777780
});
@@ -862,8 +865,11 @@ describe('processAgentFileUpload', () => {
862865
handleFileUpload: jest.fn().mockRejectedValue(new Error('PRIVATE parser failure')),
863866
});
864867
extractInspectableFileText.mockImplementationOnce(async ({ extract }) => {
865-
await extract();
866-
throw makeUninspectableExtractedTextError();
868+
try {
869+
await extract();
870+
} catch {
871+
throw makeUninspectableExtractedTextError();
872+
}
867873
});
868874
const req = makeReq({
869875
mimetype: DOCX_MIME,

packages/api/src/utils/files.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ const USER_FACING_UPLOAD_ERRORS = [
77
['Invalid file format', 'Invalid file format'],
88
['exceeds token limit', 'File content exceeds token limit'],
99
['Unable to extract text from', 'Unable to extract text from file'],
10+
['No text found in document', 'No text found in document'],
11+
['MB document parser limit', 'File exceeds the document parser size limit'],
12+
['MB per-entry decompressed cap', 'Document entry exceeds the decompressed size limit'],
13+
['total decompressed size exceeds the', 'Document exceeds the total decompressed size limit'],
14+
['MB decompressed limit', 'Document exceeds the decompressed size limit'],
15+
['MB storage limit', 'Extracted text exceeds the storage size limit'],
1016
] as const;
1117

1218
const ASCII_FILENAME_SAFE_PATTERN = /^[a-zA-Z0-9._-]$/;

0 commit comments

Comments
 (0)