Skip to content

Commit 8e9d9f6

Browse files
committed
feat(errors): ERR_NO_CRYPTO
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 1054a1c commit 8e9d9f6

File tree

7 files changed

+116
-0
lines changed

7 files changed

+116
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ This package exports the following identifiers:
168168
- `ERR_MISSING_OPTION`
169169
- `ERR_MODULE_NOT_FOUND`
170170
- `ERR_NETWORK_IMPORT_DISALLOWED`
171+
- `ERR_NO_CRYPTO`
171172
- `ERR_OPERATION_FAILED`
172173
- `ERR_PACKAGE_IMPORT_NOT_DEFINED`
173174
- `ERR_PACKAGE_PATH_NOT_EXPORTED`

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ exports[`integration:errors > ERR_MODULE_NOT_FOUND > #toString > should return s
5050

5151
exports[`integration:errors > ERR_NETWORK_IMPORT_DISALLOWED > #toString > should return string representation of error 1`] = `Error [ERR_NETWORK_IMPORT_DISALLOWED]: import of 'https://esm.sh/@flex-development/unist-util-builder' by file://\${process.cwd()}/src/__tests__/errors.integration.spec.ts is not supported: ES modules cannot be loaded by require() from the network`;
5252

53+
exports[`integration:errors > ERR_NO_CRYPTO > #toString > should return string representation of error 1`] = `Error [ERR_NO_CRYPTO]: Node.js is not compiled with OpenSSL crypto support`;
54+
5355
exports[`integration:errors > ERR_OPERATION_FAILED > #toString > should return string representation of error 1`] = `Error [ERR_OPERATION_FAILED]: Operation failed: Out of memory`;
5456

5557
exports[`integration:errors > ERR_PACKAGE_IMPORT_NOT_DEFINED > #toString > should return string representation of error 1`] = `TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier '#src' is not defined in package \${process.cwd()}/package.json imported from file://\${process.cwd()}/src/__tests__/errors.integration.spec.ts`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
3030
"ERR_MISSING_OPTION",
3131
"ERR_MODULE_NOT_FOUND",
3232
"ERR_NETWORK_IMPORT_DISALLOWED",
33+
"ERR_NO_CRYPTO",
3334
"ERR_OPERATION_FAILED",
3435
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
3536
"ERR_PACKAGE_PATH_NOT_EXPORTED",

src/__tests__/errors.integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('integration:errors', () => {
103103
import.meta.url,
104104
'ES modules cannot be loaded by require() from the network'
105105
],
106+
[codes.ERR_NO_CRYPTO, Error],
106107
[codes.ERR_OPERATION_FAILED, Error, 'Out of memory'],
107108
[
108109
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file Type Tests - ERR_NO_CRYPTO
3+
* @module errnode/errors/tests/unit-d/ERR_NO_CRYPTO
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-no-crypto'
9+
10+
describe('unit-d:errors/ERR_NO_CRYPTO', () => {
11+
describe('ERR_NO_CRYPTO', () => {
12+
it('should be ErrNoCryptoConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrNoCryptoConstructor>()
15+
})
16+
})
17+
18+
describe('ErrNoCrypto', () => {
19+
it('should extend NodeError<codes.ERR_NO_CRYPTO>', () => {
20+
expectTypeOf<TestSubject.ErrNoCrypto>()
21+
.toMatchTypeOf<NodeError<codes.ERR_NO_CRYPTO>>()
22+
})
23+
})
24+
25+
describe('ErrNoCryptoConstructor', () => {
26+
it('should match NodeErrorConstructor', () => {
27+
// Arrange
28+
type T = TestSubject.ErrNoCrypto
29+
type Args = TestSubject.ErrNoCryptoArgs
30+
31+
// Expect
32+
expectTypeOf<TestSubject.ErrNoCryptoConstructor>()
33+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
34+
})
35+
})
36+
})

src/errors/err-no-crypto.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @file Errors - ERR_NO_CRYPTO
3+
* @module errnode/errors/ERR_NO_CRYPTO
4+
* @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1603-L1604
5+
*/
6+
7+
import E from '#e'
8+
import { codes } from '#src/enums'
9+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
10+
11+
/**
12+
* `ERR_NO_CRYPTO` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_no_crypto
16+
*
17+
* @extends {NodeError<codes.ERR_NO_CRYPTO>}
18+
*/
19+
interface ErrNoCrypto extends NodeError<codes.ERR_NO_CRYPTO> {}
20+
21+
/**
22+
* `ERR_NO_CRYPTO` message arguments.
23+
*/
24+
type Args = []
25+
26+
/**
27+
* `ERR_NO_CRYPTO` constructor.
28+
*
29+
* @see {@linkcode ErrNoCrypto}
30+
* @see {@linkcode NodeErrorConstructor}
31+
*
32+
* @extends {NodeErrorConstructor<ErrNoCrypto,Args>}
33+
*/
34+
interface ErrNoCryptoConstructor
35+
extends NodeErrorConstructor<ErrNoCrypto, Args> {
36+
/**
37+
* Create a new `ERR_NO_CRYPTO` error.
38+
*
39+
* @see {@linkcode ErrNoCrypto}
40+
*
41+
* @return {ErrNoCrypto}
42+
*/
43+
new (): ErrNoCrypto
44+
}
45+
46+
/**
47+
* `ERR_NO_CRYPTO` model.
48+
*
49+
* Thrown when an attempt was made to use crypto features while Node.js was not
50+
* compiled with OpenSSL crypto support.
51+
*
52+
* @see {@linkcode ErrNoCryptoConstructor}
53+
*
54+
* @type {ErrNoCryptoConstructor}
55+
*
56+
* @class
57+
*/
58+
const ERR_NO_CRYPTO: ErrNoCryptoConstructor = E(
59+
codes.ERR_NO_CRYPTO,
60+
Error,
61+
'Node.js is not compiled with OpenSSL crypto support'
62+
)
63+
64+
export {
65+
ERR_NO_CRYPTO as default,
66+
type ErrNoCrypto,
67+
type Args as ErrNoCryptoArgs,
68+
type ErrNoCryptoConstructor
69+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ export {
154154
type ErrNetworkImportDisallowedArgs,
155155
type ErrNetworkImportDisallowedConstructor
156156
} from './err-network-import-disallowed'
157+
export {
158+
default as ERR_NO_CRYPTO,
159+
type ErrNoCrypto,
160+
type ErrNoCryptoArgs,
161+
type ErrNoCryptoConstructor
162+
} from './err-no-crypto'
157163
export {
158164
default as ERR_OPERATION_FAILED,
159165
type ErrOperationFailed,

0 commit comments

Comments
 (0)