Skip to content

Commit 2cbf2bd

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

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ This package exports the following identifiers:
160160
- `ERR_INVALID_PACKAGE_CONFIG`
161161
- `ERR_INVALID_PACKAGE_TARGET`
162162
- `ERR_INVALID_RETURN_VALUE`
163+
- `ERR_INVALID_THIS`
163164
- `ERR_INVALID_URL_SCHEME`
164165
- `ERR_INVALID_URL`
165166
- `ERR_METHOD_NOT_IMPLEMENTED`

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ exports[`integration:errors > ERR_INVALID_PACKAGE_TARGET > #toString > should re
3434

3535
exports[`integration:errors > ERR_INVALID_RETURN_VALUE > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_RETURN_VALUE]: Expected null to be returned from the 'body' function but got type number (13).`;
3636

37+
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`;
38+
3739
exports[`integration:errors > ERR_INVALID_URL > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_URL]: Invalid URL`;
3840

3941
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
@@ -22,6 +22,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
2222
"ERR_INVALID_PACKAGE_CONFIG",
2323
"ERR_INVALID_PACKAGE_TARGET",
2424
"ERR_INVALID_RETURN_VALUE",
25+
"ERR_INVALID_THIS",
2526
"ERR_INVALID_URL",
2627
"ERR_INVALID_URL_SCHEME",
2728
"ERR_METHOD_NOT_IMPLEMENTED",

src/__tests__/errors.integration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('integration:errors', () => {
8383
pathe.resolve('loader.mjs')
8484
],
8585
[codes.ERR_INVALID_RETURN_VALUE, TypeError, 'null', 'body', 13],
86+
[codes.ERR_INVALID_THIS, TypeError, 'URLSearchParams'],
8687
[codes.ERR_INVALID_URL, TypeError, pathe.sep, 'http://[127.0.0.1]:8000'],
8788
[codes.ERR_INVALID_URL_SCHEME, TypeError, 'file'],
8889
[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_THIS
3+
* @module errnode/errors/tests/unit-d/ERR_INVALID_THIS
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-invalid-this'
9+
10+
describe('unit-d:errors/ERR_INVALID_THIS', () => {
11+
describe('ERR_INVALID_THIS', () => {
12+
it('should be ErrInvalidThisConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrInvalidThisConstructor>()
15+
})
16+
})
17+
18+
describe('ErrInvalidThis', () => {
19+
it('should extend NodeError<codes.ERR_INVALID_THIS>', () => {
20+
expectTypeOf<TestSubject.ErrInvalidThis>()
21+
.toMatchTypeOf<NodeError<codes.ERR_INVALID_THIS>>()
22+
})
23+
24+
it('should extend TypeError', () => {
25+
expectTypeOf<TestSubject.ErrInvalidThis>()
26+
.toMatchTypeOf<TypeError>()
27+
})
28+
})
29+
30+
describe('ErrInvalidThisConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrInvalidThis
34+
type Args = TestSubject.ErrInvalidThisArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrInvalidThisConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})

src/errors/err-invalid-this.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file Errors - ERR_INVALID_THIS
3+
* @module errnode/errors/ERR_INVALID_THIS
4+
* @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1529
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_THIS` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_invalid_this
16+
*
17+
* @extends {NodeError<codes.ERR_INVALID_THIS>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrInvalidThis extends NodeError<codes.ERR_INVALID_THIS>, TypeError {}
21+
22+
/**
23+
* `ERR_INVALID_THIS` message arguments.
24+
*/
25+
type Args = [expected: string]
26+
27+
/**
28+
* `ERR_INVALID_THIS` constructor.
29+
*
30+
* @see {@linkcode ErrInvalidThis}
31+
* @see {@linkcode NodeErrorConstructor}
32+
*
33+
* @extends {NodeErrorConstructor<ErrInvalidThis,Args>}
34+
*/
35+
interface ErrInvalidThisConstructor
36+
extends NodeErrorConstructor<ErrInvalidThis, Args> {
37+
/**
38+
* Create a new `ERR_INVALID_THIS` error.
39+
*
40+
* @see {@linkcode ErrInvalidThis}
41+
*
42+
* @param {string} expected
43+
* Expected type of `this`
44+
* @return {ErrInvalidThis}
45+
*/
46+
new (expected: string): ErrInvalidThis
47+
}
48+
49+
/**
50+
* `ERR_INVALID_THIS` model.
51+
*
52+
* Thrown when a Node.js API function is called with an incompatible `this`
53+
* value.
54+
*
55+
* @see {@linkcode ErrInvalidThisConstructor}
56+
*
57+
* @type {ErrInvalidThisConstructor}
58+
*
59+
* @class
60+
*/
61+
const ERR_INVALID_THIS: ErrInvalidThisConstructor = E(
62+
codes.ERR_INVALID_THIS,
63+
TypeError,
64+
'Value of "this" must be of type %s'
65+
)
66+
67+
export {
68+
ERR_INVALID_THIS as default,
69+
type ErrInvalidThis,
70+
type Args as ErrInvalidThisArgs,
71+
type ErrInvalidThisConstructor
72+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export {
106106
type ErrInvalidReturnValueArgs,
107107
type ErrInvalidReturnValueConstructor
108108
} from './err-invalid-return-value'
109+
export {
110+
default as ERR_INVALID_THIS,
111+
type ErrInvalidThis,
112+
type ErrInvalidThisArgs,
113+
type ErrInvalidThisConstructor
114+
} from './err-invalid-this'
109115
export {
110116
default as ERR_INVALID_URL,
111117
type ErrInvalidUrl,

0 commit comments

Comments
 (0)