Skip to content

Commit

Permalink
internal/util: use internal/errors.js
Browse files Browse the repository at this point in the history
PR-URL: #11301
Refs: #11273
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <fhinkel@vt.edu>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
seppevs authored and tniessen committed Jun 15, 2017
1 parent c7323af commit de4a749
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ Used when data cannot be sent on a socket.

Used when a call is made and the UDP subsystem is not running.

<a id="ERR_NO_CRYPTO"></a>
### ERR_NO_CRYPTO

Used when an attempt is made to use crypto features while Node.js is not
compiled with OpenSSL crypto support.

<a id="ERR_STDERR_CLOSE"></a>
### ERR_STDERR_CLOSE

Expand Down
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
E('ERR_MISSING_ARGS', missingArgs);
E('ERR_PARSE_HISTORY_DATA',
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
E('ERR_TRANSFORM_ALREADY_TRANSFORMING',
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function deprecate(fn, msg, code) {
}

if (code !== undefined && typeof code !== 'string')
throw new TypeError('`code` argument must be a string');
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'string');

var warned = false;
function deprecated(...args) {
Expand Down Expand Up @@ -79,7 +79,7 @@ function decorateErrorStack(err) {

function assertCrypto() {
if (noCrypto)
throw new Error('Node.js is not compiled with openssl crypto support');
throw new errors.Error('ERR_NO_CRYPTO');
}

// The loop should only run at most twice, retrying with lowercased enc
Expand Down
12 changes: 7 additions & 5 deletions test/parallel/test-internal-util-assertCrypto.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Flags: --expose-internals
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const util = require('internal/util');

const expectedError = common.expectsError({
code: 'ERR_NO_CRYPTO',
type: Error
});

if (!process.versions.openssl) {
assert.throws(
() => util.assertCrypto(),
/^Error: Node\.js is not compiled with openssl crypto support$/
);
assert.throws(() => util.assertCrypto(), expectedError);
} else {
assert.doesNotThrow(() => util.assertCrypto());
}

0 comments on commit de4a749

Please sign in to comment.