1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Attempt to improve the PDFDocument error message for empty files (issue 5887)

Given that the error in question is surfaced on the API-side, this patch makes the following changes:
 - Updates the wording such that it'll hopefully be slightly easier for users to understand.
 - Changes the plain `Error` to an `InvalidPDFException` instead, since that should work better with the existing Error handling.
 - Adds a unit-test which loads an empty PDF document (and also improves a pre-existing `InvalidPDFException` message and its test-case).
This commit is contained in:
Jonas Jenwald 2019-12-09 15:00:45 +01:00
parent a6db045789
commit b00835f589
3 changed files with 24 additions and 7 deletions

View file

@ -15,9 +15,9 @@
/* eslint no-var: error */
import {
assert, bytesToString, FormatError, info, isArrayBuffer, isArrayEqual, isBool,
isNum, isSpace, isString, OPS, shadow, stringToBytes, stringToPDFString, Util,
warn
assert, bytesToString, FormatError, info, InvalidPDFException, isArrayBuffer,
isArrayEqual, isBool, isNum, isSpace, isString, OPS, shadow, stringToBytes,
stringToPDFString, Util, warn
} from '../shared/util';
import { Catalog, ObjectLoader, XRef } from './obj';
import { Dict, isDict, isName, isStream, Ref } from './primitives';
@ -375,7 +375,8 @@ class PDFDocument {
throw new Error('PDFDocument: Unknown argument type');
}
if (stream.length <= 0) {
throw new Error('PDFDocument: Stream must have data');
throw new InvalidPDFException(
'The PDF file is empty, i.e. its size is zero bytes.');
}
this.pdfManager = pdfManager;