Merge pull request #604 from justinmchase/fix/590-preserve-error-stack
Fix/590 preserve error stack
This commit is contained in:
commit
8aeb08054f
|
@ -551,7 +551,10 @@ function onError(message, error) {
|
||||||
// log the stack trace
|
// log the stack trace
|
||||||
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
|
||||||
throw new Error(message + ': ' + error.message);
|
const newError = new Error(message + ': ' + error.message);
|
||||||
|
newError.innerError = error;
|
||||||
|
newError.stack += '\n' + error.stack;
|
||||||
|
throw newError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1200,6 +1200,35 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Errors', function() {
|
||||||
|
it('Errors stack should contain the stack of 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.stack).to.match(/\nError: No keys or passwords/);
|
||||||
|
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