Skip to content

Commit 84330ce

Browse files
committed
feat(errors): ERR_ARG_NOT_ITERABLE
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 678a2cb commit 84330ce

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

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_ARG_NOT_ITERABLE > #toString > should return string representation of error 1`] = `TypeError [ERR_ARG_NOT_ITERABLE]: Query pairs must be iterable`;
4+
35
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`;
46

57
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'`;

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_ARG_NOT_ITERABLE",
89
"ERR_ENCODING_NOT_SUPPORTED",
910
"ERR_IMPORT_ASSERTION_TYPE_FAILED",
1011
"ERR_IMPORT_ASSERTION_TYPE_MISSING",

src/__tests__/errors.integration.spec.ts

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

2323
describe.each<[keyof typeof testSubject, ErrorConstructor, ...unknown[]]>([
24+
[codes.ERR_ARG_NOT_ITERABLE, TypeError, 'Query pairs'],
2425
[codes.ERR_ENCODING_NOT_SUPPORTED, RangeError, null],
2526
[
2627
codes.ERR_IMPORT_ASSERTION_TYPE_FAILED,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - ERR_ARG_NOT_ITERABLE
3+
* @module errnode/errors/tests/unit-d/ERR_ARG_NOT_ITERABLE
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-arg-not-iterable'
9+
10+
describe('unit-d:errors/ERR_ARG_NOT_ITERABLE', () => {
11+
describe('ERR_ARG_NOT_ITERABLE', () => {
12+
it('should be ErrArgNotIterableConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrArgNotIterableConstructor>()
15+
})
16+
})
17+
18+
describe('ErrArgNotIterable', () => {
19+
it('should extend NodeError<codes.ERR_ARG_NOT_ITERABLE>', () => {
20+
expectTypeOf<TestSubject.ErrArgNotIterable>()
21+
.toMatchTypeOf<NodeError<codes.ERR_ARG_NOT_ITERABLE>>()
22+
})
23+
24+
it('should extend TypeError', () => {
25+
expectTypeOf<TestSubject.ErrArgNotIterable>()
26+
.toMatchTypeOf<TypeError>()
27+
})
28+
})
29+
30+
describe('ErrArgNotIterableConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrArgNotIterable
34+
type Args = TestSubject.ErrArgNotIterableArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrArgNotIterableConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})

src/errors/err-arg-not-iterable.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @file Errors - ERR_ARG_NOT_ITERABLE
3+
* @module errnode/errors/ERR_ARG_NOT_ITERABLE
4+
* @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1122
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_ARG_NOT_ITERABLE` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_arg_not_iterable
16+
*
17+
* @extends {NodeError<codes.ERR_ARG_NOT_ITERABLE>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrArgNotIterable
21+
extends NodeError<codes.ERR_ARG_NOT_ITERABLE>, TypeError {}
22+
23+
/**
24+
* `ERR_ARG_NOT_ITERABLE` message arguments.
25+
*/
26+
type Args = [arg: unknown]
27+
28+
/**
29+
* `ERR_ARG_NOT_ITERABLE` constructor.
30+
*
31+
* @see {@linkcode ErrArgNotIterable}
32+
* @see {@linkcode NodeErrorConstructor}
33+
*
34+
* @extends {NodeErrorConstructor<ErrArgNotIterable,Args>}
35+
*/
36+
interface ErrArgNotIterableConstructor
37+
extends NodeErrorConstructor<ErrArgNotIterable, Args> {
38+
/**
39+
* Create a new `ERR_ARG_NOT_ITERABLE` error.
40+
*
41+
* @see {@linkcode ErrArgNotIterable}
42+
*
43+
* @param {unknown} arg
44+
* Description of non-iterable argument, or the non-iterable argument
45+
* @return {ErrArgNotIterable}
46+
*/
47+
new (arg: unknown): ErrArgNotIterable
48+
}
49+
50+
/**
51+
* `ERR_ARG_NOT_ITERABLE` model.
52+
*
53+
* Thrown when an iterable argument (i.e. a value that works with `for...of`
54+
* loops) is required, but not provided to a Node.js API.
55+
*
56+
* @see {@linkcode ErrArgNotIterableConstructor}
57+
*
58+
* @type {ErrArgNotIterableConstructor}
59+
*
60+
* @class
61+
*/
62+
const ERR_ARG_NOT_ITERABLE: ErrArgNotIterableConstructor = E(
63+
codes.ERR_ARG_NOT_ITERABLE,
64+
TypeError,
65+
'%s must be iterable'
66+
)
67+
68+
export {
69+
ERR_ARG_NOT_ITERABLE as default,
70+
type ErrArgNotIterable,
71+
type Args as ErrArgNotIterableArgs,
72+
type ErrArgNotIterableConstructor
73+
}

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_ARG_NOT_ITERABLE,
9+
type ErrArgNotIterable,
10+
type ErrArgNotIterableArgs,
11+
type ErrArgNotIterableConstructor
12+
} from './err-arg-not-iterable'
713
export {
814
default as ERR_ENCODING_NOT_SUPPORTED,
915
type ErrEncodingNotSupported,

0 commit comments

Comments
 (0)