Skip to content
Closed
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
Prev Previous commit
Next Next commit
errors: add CryptoError
A new internal/errors type that provides access to the
`opensslErrorStack`, code, and message.
  • Loading branch information
jasnell committed Oct 30, 2017
commit 6ed4fb8a856c494d513e4f04d483c3f470d0a9ba
21 changes: 21 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// message may change, the code should not.

const kCode = Symbol('code');
const kInfo = Symbol('info');
const messages = new Map();

const { kMaxLength } = process.binding('buffer');
Expand Down Expand Up @@ -58,6 +59,25 @@ function makeNodeError(Base) {
};
}

class CryptoError extends makeNodeError(Error) {
constructor(key, context, ...args) {
super(key, args);
Object.defineProperty(this, kInfo, {
value: context || {},
enumerable: false,
configurable: false
});
}

get info() {
return this[kInfo];
}

get opensslErrorStack() {
return this[kInfo].opensslErrorStack;
}
}

class AssertionError extends Error {
constructor(options) {
if (typeof options !== 'object' || options === null) {
Expand Down Expand Up @@ -128,6 +148,7 @@ module.exports = exports = {
RangeError: makeNodeError(RangeError),
URIError: makeNodeError(URIError),
AssertionError,
CryptoError,
E // This is exported only to facilitate testing.
};

Expand Down