Error object cannot be used with structured clone, pass stack
This commit is contained in:
parent
2a9a1b4846
commit
49695ff50c
|
@ -552,7 +552,7 @@ function onError(message, error) {
|
||||||
if (config.debug) { console.error(error.stack); }
|
if (config.debug) { console.error(error.stack); }
|
||||||
// rethrow new high level error for api users
|
// rethrow new high level error for api users
|
||||||
const newError = new Error(message + ': ' + error.message);
|
const newError = new Error(message + ': ' + error.message);
|
||||||
newError.innerError = error;
|
//newError.innerError = error;
|
||||||
newError.stack += '\n' + error.stack;
|
newError.stack += '\n' + error.stack;
|
||||||
throw newError;
|
throw newError;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,9 @@ AsyncProxy.prototype.onMessage = function(event) {
|
||||||
case 'method-return':
|
case 'method-return':
|
||||||
if (msg.err) {
|
if (msg.err) {
|
||||||
// fail
|
// fail
|
||||||
this.tasks[msg.id].reject(new Error(msg.err));
|
const err = new Error(msg.err);
|
||||||
|
err.stack = msg.stack || err.stack;
|
||||||
|
this.tasks[msg.id].reject(err);
|
||||||
} else {
|
} else {
|
||||||
// success
|
// success
|
||||||
this.tasks[msg.id].resolve(msg.data);
|
this.tasks[msg.id].resolve(msg.data);
|
||||||
|
|
|
@ -86,7 +86,7 @@ function delegate(id, method, options) {
|
||||||
// clone packets (for web worker structured cloning algorithm)
|
// clone packets (for web worker structured cloning algorithm)
|
||||||
response({ id:id, event:'method-return', data:openpgp.packet.clone.clonePackets(data) });
|
response({ id:id, event:'method-return', data:openpgp.packet.clone.clonePackets(data) });
|
||||||
}).catch(function(e) {
|
}).catch(function(e) {
|
||||||
response({ id:id, event:'method-return', err:e.message });
|
response({ id:id, event:'method-return', err:e.message, stack:e.stack });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1202,8 +1202,8 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Errors', function() {
|
describe('Errors', function() {
|
||||||
it('Errors stack should contain the stack of innerError', function(done) {
|
it('Error stack should contain the stack of the original error', function(done) {
|
||||||
openpgp.encrypt({
|
return openpgp.encrypt({
|
||||||
data: new Uint8Array([0x01, 0x01, 0x01]),
|
data: new Uint8Array([0x01, 0x01, 0x01]),
|
||||||
passwords: null
|
passwords: null
|
||||||
})
|
})
|
||||||
|
@ -1213,22 +1213,22 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
expect(error.stack).to.match(/\nError: No keys or passwords/);
|
expect(error.stack).to.match(/\nError: No keys or passwords/);
|
||||||
done();
|
done();
|
||||||
});
|
|
||||||
});
|
|
||||||
it('Errors should contain innerError', function(done) {
|
|
||||||
openpgp.encrypt({
|
|
||||||
data: new Uint8Array([0x01, 0x01, 0x01]),
|
|
||||||
passwords: null
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
|
||||||
done(new Error('Error expected.'));
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
expect(error.innerError).to.exist;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
})
|
// it('Errors should contain innerError', function(done) {
|
||||||
|
// openpgp.encrypt({
|
||||||
|
// data: new Uint8Array([0x01, 0x01, 0x01]),
|
||||||
|
// passwords: null
|
||||||
|
// })
|
||||||
|
// .then(function() {
|
||||||
|
// done(new Error('Error expected.'));
|
||||||
|
// })
|
||||||
|
// .catch(function(error) {
|
||||||
|
// expect(error.innerError).to.exist;
|
||||||
|
// done();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user