Skip to content

Commit f33bef4

Browse files
committed
feat(errors): ERR_ENCODING_NOT_SUPPORTED
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 2302af2 commit f33bef4

File tree

7 files changed

+128
-0
lines changed

7 files changed

+128
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ This package exports the following identifiers:
143143
- [`codes`](#codes)
144144
- [`determineSpecificType`](#determinespecifictypevalue)
145145
- [`errors`](#errors)
146+
- `ERR_ENCODING_NOT_SUPPORTED`
146147
- `ERR_IMPORT_ASSERTION_TYPE_FAILED`
147148
- `ERR_IMPORT_ASSERTION_TYPE_MISSING`
148149
- `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`integration:errors > ERR_ENCODING_NOT_SUPPORTED > #toString > should return string representation of error 1`] = `RangeError [ERR_ENCODING_NOT_SUPPORTED]: The "null" encoding is not supported`;
4+
35
exports[`integration:errors > ERR_IMPORT_ASSERTION_TYPE_FAILED > #toString > should return string representation of error 1`] = `TypeError [ERR_IMPORT_ASSERTION_TYPE_FAILED]: Module '\${process.cwd()}/build.config.ts' is not of type 'json'`;
46

57
exports[`integration:errors > ERR_IMPORT_ASSERTION_TYPE_MISSING > #toString > should return string representation of error 1`] = `TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module '\${process.cwd()}/package.json' needs an import assertion of type 'json'`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
55
"E",
66
"codes",
77
"syscodes",
8+
"ERR_ENCODING_NOT_SUPPORTED",
89
"ERR_IMPORT_ASSERTION_TYPE_FAILED",
910
"ERR_IMPORT_ASSERTION_TYPE_MISSING",
1011
"ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED",

src/__tests__/errors.integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('integration:errors', () => {
1919
})
2020

2121
describe.each<[keyof typeof testSubject, ErrorConstructor, ...unknown[]]>([
22+
[codes.ERR_ENCODING_NOT_SUPPORTED, RangeError, null],
2223
[
2324
codes.ERR_IMPORT_ASSERTION_TYPE_FAILED,
2425
TypeError,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - ERR_ENCODING_NOT_SUPPORTED
3+
* @module errnode/errors/tests/unit-d/ERR_ENCODING_NOT_SUPPORTED
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-encoding-not-supported'
9+
10+
describe('unit-d:errors/ERR_ENCODING_NOT_SUPPORTED', () => {
11+
describe('ERR_ENCODING_NOT_SUPPORTED', () => {
12+
it('should be ErrEncodingNotSupportedConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrEncodingNotSupportedConstructor>()
15+
})
16+
})
17+
18+
describe('ErrEncodingNotSupported', () => {
19+
it('should extend NodeError<codes.ERR_ENCODING_NOT_SUPPORTED>', () => {
20+
expectTypeOf<TestSubject.ErrEncodingNotSupported>()
21+
.toMatchTypeOf<NodeError<codes.ERR_ENCODING_NOT_SUPPORTED>>()
22+
})
23+
24+
it('should extend RangeError', () => {
25+
expectTypeOf<TestSubject.ErrEncodingNotSupported>()
26+
.toMatchTypeOf<RangeError>()
27+
})
28+
})
29+
30+
describe('ErrEncodingNotSupportedConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrEncodingNotSupported
34+
type Args = TestSubject.ErrEncodingNotSupportedArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrEncodingNotSupportedConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @file Errors - ERR_ENCODING_NOT_SUPPORTED
3+
* @module errnode/errors/ERR_ENCODING_NOT_SUPPORTED
4+
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1198-L1199
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_ENCODING_NOT_SUPPORTED` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_encoding_not_supported
16+
*
17+
* @extends {NodeError<codes.ERR_ENCODING_NOT_SUPPORTED>}
18+
* @extends {RangeError}
19+
*/
20+
interface ErrEncodingNotSupported
21+
extends NodeError<codes.ERR_ENCODING_NOT_SUPPORTED>, RangeError {}
22+
23+
/**
24+
* `ERR_ENCODING_NOT_SUPPORTED` message arguments.
25+
*/
26+
type Args = [encoding: unknown]
27+
28+
/**
29+
* `ERR_ENCODING_NOT_SUPPORTED` constructor.
30+
*
31+
* @see {@linkcode Args}
32+
* @see {@linkcode ErrEncodingNotSupported}
33+
* @see {@linkcode NodeErrorConstructor}
34+
*
35+
* @extends {NodeErrorConstructor<ErrEncodingNotSupported,Args>}
36+
*/
37+
interface ErrEncodingNotSupportedConstructor
38+
extends NodeErrorConstructor<ErrEncodingNotSupported, Args> {
39+
/**
40+
* Create a new `ERR_ENCODING_NOT_SUPPORTED` error.
41+
*
42+
* @see {@linkcode ErrEncodingNotSupported}
43+
*
44+
* @param {unknown} encoding
45+
* The encoding that is not supported
46+
* @return {ErrEncodingNotSupported}
47+
*/
48+
new (encoding: unknown): ErrEncodingNotSupported
49+
}
50+
51+
/**
52+
* `ERR_ENCODING_NOT_SUPPORTED` model.
53+
*
54+
* Thrown when an encoding provided to the `TextDecoder()` API is not one of the
55+
* [WHATWG Supported Encodings][1].
56+
*
57+
* [1]: https://nodejs.org/api/util.html#whatwg-supported-encodings
58+
*
59+
* @see {@linkcode ErrEncodingNotSupportedConstructor}
60+
*
61+
* @type {ErrEncodingNotSupportedConstructor}
62+
*
63+
* @class
64+
*/
65+
const ERR_ENCODING_NOT_SUPPORTED: ErrEncodingNotSupportedConstructor = E(
66+
codes.ERR_ENCODING_NOT_SUPPORTED,
67+
RangeError,
68+
'The "%s" encoding is not supported'
69+
)
70+
71+
export {
72+
ERR_ENCODING_NOT_SUPPORTED as default,
73+
type ErrEncodingNotSupported,
74+
type Args as ErrEncodingNotSupportedArgs,
75+
type ErrEncodingNotSupportedConstructor
76+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
* @see https://nodejs.org/api/errors.html#nodejs-error-codes
55
*/
66

7+
export {
8+
default as ERR_ENCODING_NOT_SUPPORTED,
9+
type ErrEncodingNotSupported,
10+
type ErrEncodingNotSupportedArgs,
11+
type ErrEncodingNotSupportedConstructor
12+
} from './err-encoding-not-supported'
713
export {
814
default as ERR_IMPORT_ASSERTION_TYPE_FAILED,
915
type ErrImportAssertionTypeFailed,

0 commit comments

Comments
 (0)