Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the exception propagation when rejecting workerReadyCapability #5275

Merged
merged 5 commits into from
Sep 16, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix the exception propagation when rejecting workerReadyCapability
Currently when an exception is thrown, we try to reject `workerReadyCapability` with multiple arguments in src/core/api.js. This obviously doesn't work, hence this patch changes that to instead reject with the exception object as is.
In src/core/worker.js the exception is currently (unncessarily) wrapped in an object, so this patch also simplifies that to directly send the exception object instead.
  • Loading branch information
Snuffleupagus committed Sep 8, 2014
commit ca027ebfdb1ee101e71ec74d6ad1e83b4c78a053
23 changes: 7 additions & 16 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
if (status === 404) {
var exception = new MissingPDFException('Missing PDF "' +
source.url + '".');
handler.send('MissingPDF', { exception: exception });
handler.send('MissingPDF', exception);
} else {
handler.send('DocError', 'Unexpected server response (' +
status + ') while retrieving PDF "' +
Expand Down Expand Up @@ -200,26 +200,17 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
var onFailure = function(e) {
if (e instanceof PasswordException) {
if (e.code === PasswordResponses.NEED_PASSWORD) {
handler.send('NeedPassword', {
exception: e
});
handler.send('NeedPassword', e);
} else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
handler.send('IncorrectPassword', {
exception: e
});
handler.send('IncorrectPassword', e);
}
} else if (e instanceof InvalidPDFException) {
handler.send('InvalidPDF', {
exception: e
});
handler.send('InvalidPDF', e);
} else if (e instanceof MissingPDFException) {
handler.send('MissingPDF', {
exception: e
});
handler.send('MissingPDF', e);
} else {
handler.send('UnknownError', {
exception: new UnknownErrorException(e.message, e.toString())
});
handler.send('UnknownError',
new UnknownErrorException(e.message, e.toString()));
}
};

Expand Down
42 changes: 23 additions & 19 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals CanvasGraphics, combineUrl, createScratchCanvas, error,
FontLoader, globalScope, info, isArrayBuffer, loadJpegStream,
MessageHandler, PDFJS, Promise, StatTimer, warn,
PasswordResponses, Util, loadScript, createPromiseCapability,
FontFace */
/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
createScratchCanvas, Promise, CanvasGraphics */

'use strict';

Expand Down Expand Up @@ -865,36 +865,40 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.workerReadyCapability.resolve(pdfDocument);
}, this);

messageHandler.on('NeedPassword', function transportPassword(data) {
messageHandler.on('NeedPassword',
function transportNeedPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.NEED_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);

messageHandler.on('IncorrectPassword', function transportBadPass(data) {
messageHandler.on('IncorrectPassword',
function transportIncorrectPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.INCORRECT_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);

messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
this.workerReadyCapability.reject(data.exception.name, data.exception);
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
this.workerReadyCapability.reject(
new InvalidPDFException(exception.message));
}, this);

messageHandler.on('MissingPDF', function transportMissingPDF(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
this.workerReadyCapability.reject(
new MissingPDFException(exception.message));
}, this);

messageHandler.on('UnknownError', function transportUnknownError(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
messageHandler.on('UnknownError',
function transportUnknownError(exception) {
this.workerReadyCapability.reject(
new UnknownErrorException(exception.message, exception.details));
}, this);

messageHandler.on('DataLoaded', function transportPage(data) {
Expand Down
15 changes: 10 additions & 5 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,24 +672,29 @@ var PDFView = {
self.load(pdfDocument, scale);
self.loading = false;
},
function getDocumentError(message, exception) {
function getDocumentError(exception) {
var name, message;
if (exception) {
name = exception.name;
message = exception.message;
}
var loadingErrorMessage = mozL10n.get('loading_error', null,
'An error occurred while loading the PDF.');

if (exception && exception.name === 'InvalidPDFException') {
if (name === 'InvalidPDFException') {
// change error message also for other builds
loadingErrorMessage = mozL10n.get('invalid_file_error', null,
'Invalid or corrupted PDF file.');
'Invalid or corrupted PDF file.');
//#if B2G
// window.alert(loadingErrorMessage);
// return window.close();
//#endif
}

if (exception && exception.name === 'MissingPDFException') {
if (name === 'MissingPDFException') {
// special message for missing PDF's
loadingErrorMessage = mozL10n.get('missing_file_error', null,
'Missing PDF file.');
'Missing PDF file.');

//#if B2G
// window.alert(loadingErrorMessage);
Expand Down