diff --git a/doc/api/errors.md b/doc/api/errors.md
index 9138da3115b0d8..aef6580822859e 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -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.
+
+### ERR_NO_CRYPTO
+
+Used when an attempt is made to use crypto features while Node.js is not
+compiled with OpenSSL crypto support.
+
### ERR_STDERR_CLOSE
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 570ed6d5ba6b42..fcfbdd24bf3925 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -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',
diff --git a/lib/internal/util.js b/lib/internal/util.js
index a77089b6833cd1..efdd7e0fd277b3 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -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) {
@@ -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
diff --git a/test/parallel/test-internal-util-assertCrypto.js b/test/parallel/test-internal-util-assertCrypto.js
index 9d1c923255a0e8..d1387e489e1dfc 100644
--- a/test/parallel/test-internal-util-assertCrypto.js
+++ b/test/parallel/test-internal-util-assertCrypto.js
@@ -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());
}