Skip to content

Commit de4a749

Browse files
seppevstniessen
authored andcommitted
internal/util: use internal/errors.js
PR-URL: #11301 Refs: #11273 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent c7323af commit de4a749

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

doc/api/errors.md

+6
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ Used when data cannot be sent on a socket.
748748

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

751+
<a id="ERR_NO_CRYPTO"></a>
752+
### ERR_NO_CRYPTO
753+
754+
Used when an attempt is made to use crypto features while Node.js is not
755+
compiled with OpenSSL crypto support.
756+
751757
<a id="ERR_STDERR_CLOSE"></a>
752758
### ERR_STDERR_CLOSE
753759

lib/internal/errors.js

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks');
155155
E('ERR_MISSING_ARGS', missingArgs);
156156
E('ERR_PARSE_HISTORY_DATA',
157157
(oldHistoryPath) => `Could not parse history data in ${oldHistoryPath}`);
158+
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
158159
E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed');
159160
E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed');
160161
E('ERR_TRANSFORM_ALREADY_TRANSFORMING',

lib/internal/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function deprecate(fn, msg, code) {
3434
}
3535

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

3939
var warned = false;
4040
function deprecated(...args) {
@@ -79,7 +79,7 @@ function decorateErrorStack(err) {
7979

8080
function assertCrypto() {
8181
if (noCrypto)
82-
throw new Error('Node.js is not compiled with openssl crypto support');
82+
throw new errors.Error('ERR_NO_CRYPTO');
8383
}
8484

8585
// The loop should only run at most twice, retrying with lowercased enc
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Flags: --expose-internals
22
'use strict';
3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const util = require('internal/util');
66

7+
const expectedError = common.expectsError({
8+
code: 'ERR_NO_CRYPTO',
9+
type: Error
10+
});
11+
712
if (!process.versions.openssl) {
8-
assert.throws(
9-
() => util.assertCrypto(),
10-
/^Error: Node\.js is not compiled with openssl crypto support$/
11-
);
13+
assert.throws(() => util.assertCrypto(), expectedError);
1214
} else {
1315
assert.doesNotThrow(() => util.assertCrypto());
1416
}

0 commit comments

Comments
 (0)