Skip to content

Commit 1054a1c

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

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ This package exports the following identifiers:
161161
- `ERR_INVALID_PACKAGE_TARGET`
162162
- `ERR_INVALID_RETURN_VALUE`
163163
- `ERR_INVALID_THIS`
164+
- `ERR_INVALID_TUPLE`
164165
- `ERR_INVALID_URL_SCHEME`
165166
- `ERR_INVALID_URL`
166167
- `ERR_METHOD_NOT_IMPLEMENTED`

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ exports[`integration:errors > ERR_INVALID_RETURN_VALUE > #toString > should retu
3636

3737
exports[`integration:errors > ERR_INVALID_THIS > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_THIS]: Value of "this" must be of type URLSearchParams`;
3838

39+
exports[`integration:errors > ERR_INVALID_TUPLE > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_TUPLE]: Each query pair must be an iterable [name, value] tuple`;
40+
3941
exports[`integration:errors > ERR_INVALID_URL > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_URL]: Invalid URL`;
4042

4143
exports[`integration:errors > ERR_INVALID_URL_SCHEME > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
2323
"ERR_INVALID_PACKAGE_TARGET",
2424
"ERR_INVALID_RETURN_VALUE",
2525
"ERR_INVALID_THIS",
26+
"ERR_INVALID_TUPLE",
2627
"ERR_INVALID_URL",
2728
"ERR_INVALID_URL_SCHEME",
2829
"ERR_METHOD_NOT_IMPLEMENTED",

src/__tests__/errors.integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe('integration:errors', () => {
8484
],
8585
[codes.ERR_INVALID_RETURN_VALUE, TypeError, 'null', 'body', 13],
8686
[codes.ERR_INVALID_THIS, TypeError, 'URLSearchParams'],
87+
[codes.ERR_INVALID_TUPLE, TypeError, 'Each query pair', '[name, value]'],
8788
[codes.ERR_INVALID_URL, TypeError, pathe.sep, 'http://[127.0.0.1]:8000'],
8889
[codes.ERR_INVALID_URL_SCHEME, TypeError, 'file'],
8990
[codes.ERR_METHOD_NOT_IMPLEMENTED, Error, '_transform()'],
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - ERR_INVALID_TUPLE
3+
* @module errnode/errors/tests/unit-d/ERR_INVALID_TUPLE
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-invalid-tuple'
9+
10+
describe('unit-d:errors/ERR_INVALID_TUPLE', () => {
11+
describe('ERR_INVALID_TUPLE', () => {
12+
it('should be ErrInvalidTupleConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrInvalidTupleConstructor>()
15+
})
16+
})
17+
18+
describe('ErrInvalidTuple', () => {
19+
it('should extend NodeError<codes.ERR_INVALID_TUPLE>', () => {
20+
expectTypeOf<TestSubject.ErrInvalidTuple>()
21+
.toMatchTypeOf<NodeError<codes.ERR_INVALID_TUPLE>>()
22+
})
23+
24+
it('should extend TypeError', () => {
25+
expectTypeOf<TestSubject.ErrInvalidTuple>()
26+
.toMatchTypeOf<TypeError>()
27+
})
28+
})
29+
30+
describe('ErrInvalidTupleConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrInvalidTuple
34+
type Args = TestSubject.ErrInvalidTupleArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrInvalidTupleConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})

src/errors/err-invalid-tuple.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* @file Errors - ERR_INVALID_TUPLE
3+
* @module errnode/errors/ERR_INVALID_TUPLE
4+
* @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1530
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_INVALID_TUPLE` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_invalid_tuple
16+
*
17+
* @extends {NodeError<codes.ERR_INVALID_TUPLE>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrInvalidTuple
21+
extends NodeError<codes.ERR_INVALID_TUPLE>, TypeError {}
22+
23+
/**
24+
* `ERR_INVALID_TUPLE` message arguments.
25+
*/
26+
type Args = [description: string, tuple: string]
27+
28+
/**
29+
* `ERR_INVALID_TUPLE` constructor.
30+
*
31+
* @see {@linkcode ErrInvalidTuple}
32+
* @see {@linkcode NodeErrorConstructor}
33+
*
34+
* @extends {NodeErrorConstructor<ErrInvalidTuple,Args>}
35+
*/
36+
interface ErrInvalidTupleConstructor
37+
extends NodeErrorConstructor<ErrInvalidTuple, Args> {
38+
/**
39+
* Create a new `ERR_INVALID_TUPLE` error.
40+
*
41+
* @see {@linkcode ErrInvalidTuple}
42+
*
43+
* @param {string} description
44+
* Description of required tuple
45+
* @param {string} tuple
46+
* String representation of tuple
47+
* @return {ErrInvalidTuple}
48+
*/
49+
new (description: string, tuple: string): ErrInvalidTuple
50+
}
51+
52+
/**
53+
* `ERR_INVALID_TUPLE` model.
54+
*
55+
* Thrown when an element in the iterable provided to the [WHATWG][whatwg]
56+
* [`URLSearchParams` constructor][constructor] did not represent a
57+
* `[name, value]` tuple.
58+
*
59+
* [constructor]: https://nodejs.org/api/url.html#new-urlsearchparamsiterable
60+
* [whatwg]: https://nodejs.org/api/url.html#the-whatwg-url-api
61+
*
62+
* @see {@linkcode ErrInvalidTupleConstructor}
63+
*
64+
* @type {ErrInvalidTupleConstructor}
65+
*
66+
* @class
67+
*/
68+
const ERR_INVALID_TUPLE: ErrInvalidTupleConstructor = E(
69+
codes.ERR_INVALID_TUPLE,
70+
TypeError,
71+
'%s must be an iterable %s tuple'
72+
)
73+
74+
export {
75+
ERR_INVALID_TUPLE as default,
76+
type ErrInvalidTuple,
77+
type Args as ErrInvalidTupleArgs,
78+
type ErrInvalidTupleConstructor
79+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export {
112112
type ErrInvalidThisArgs,
113113
type ErrInvalidThisConstructor
114114
} from './err-invalid-this'
115+
export {
116+
default as ERR_INVALID_TUPLE,
117+
type ErrInvalidTuple,
118+
type ErrInvalidTupleArgs,
119+
type ErrInvalidTupleConstructor
120+
} from './err-invalid-tuple'
115121
export {
116122
default as ERR_INVALID_URL,
117123
type ErrInvalidUrl,

0 commit comments

Comments
 (0)