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

internal/util: use internal/errors.js #11301

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
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());
}