Skip to content

Commit c6305f8

Browse files
committed
feat(errors): ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent cb549e9 commit c6305f8

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ This package exports the following identifiers:
148148
- `ERR_IMPORT_ASSERTION_TYPE_MISSING`
149149
- `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`
150150
- `ERR_IMPORT_ATTRIBUTE_MISSING`
151+
- `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE`
151152
- `ERR_INCOMPATIBLE_OPTION_PAIR`
152153
- `ERR_INVALID_ARG_TYPE`
153154
- `ERR_INVALID_ARG_VALUE`

__fixtures__/js-module-data-url.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Fixtures - JS_MODULE_DATA_URL
3+
* @module fixtures/JS_MODULE_DATA_URL
4+
*/
5+
6+
/**
7+
* JavaScript module `data:` URL.
8+
*
9+
* @const {string} JS_MODULE_DATA_URL
10+
*/
11+
const JS_MODULE_DATA_URL: string = 'data:text/javascript,export{}'
12+
13+
export default JS_MODULE_DATA_URL

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ exports[`integration:errors > ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED > #toString
1010

1111
exports[`integration:errors > ERR_IMPORT_ATTRIBUTE_MISSING > #toString > should return string representation of error 1`] = `TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module "data:application/json,""" needs an import attribute of "type: json"`;
1212

13+
exports[`integration:errors > ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE > #toString > should return string representation of error 1`] = `TypeError [ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE]: Module "data:text/javascript,export{}" is not of type "json"`;
14+
1315
exports[`integration:errors > ERR_INCOMPATIBLE_OPTION_PAIR > #toString > should return string representation of error 1`] = `TypeError [ERR_INCOMPATIBLE_OPTION_PAIR]: Option 'N' cannot be used in combination with option 'cost'`;
1416

1517
exports[`integration:errors > ERR_INVALID_ARG_TYPE > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_ARG_TYPE]: The 'ctor' argument must be of type function. Received null`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
1010
"ERR_IMPORT_ASSERTION_TYPE_MISSING",
1111
"ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED",
1212
"ERR_IMPORT_ATTRIBUTE_MISSING",
13+
"ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE",
1314
"ERR_INCOMPATIBLE_OPTION_PAIR",
1415
"ERR_INVALID_ARG_TYPE",
1516
"ERR_INVALID_ARG_VALUE",

src/__tests__/errors.integration.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @module errnode/tests/integration/errors
44
*/
55

6+
import JS_MODULE_DATA_URL from '#fixtures/js-module-data-url'
67
import JSON_MODULE_DATA_URL from '#fixtures/json-module-data-url'
78
import { codes, syscodes } from '#src/enums'
89
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
@@ -41,6 +42,12 @@ describe('integration:errors', () => {
4142
'type',
4243
'json'
4344
],
45+
[
46+
codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
47+
TypeError,
48+
JS_MODULE_DATA_URL,
49+
'json'
50+
],
4451
[codes.ERR_INCOMPATIBLE_OPTION_PAIR, TypeError, 'N', 'cost'],
4552
[codes.ERR_INVALID_ARG_TYPE, TypeError, 'ctor', 'Function', null],
4653
[codes.ERR_INVALID_ARG_VALUE, TypeError, 'address', 1],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @file Type Tests - ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
3+
* @module errnode/errors/tests/unit-d/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-import-attribute-type-incompatible'
9+
10+
describe('unit-d:errors/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE', () => {
11+
describe('ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE', () => {
12+
it('should be ErrImportAttributeTypeIncompatibleConstructor', () => {
13+
// Arrange
14+
type Expect = TestSubject.ErrImportAttributeTypeIncompatibleConstructor
15+
16+
// Expect
17+
expectTypeOf<typeof TestSubject.default>().toEqualTypeOf<Expect>()
18+
})
19+
})
20+
21+
describe('ErrImportAttributeTypeIncompatible', () => {
22+
it('should extend NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>', () => {
23+
// Arrange
24+
type Expect = NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>
25+
26+
// Expect
27+
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatible>()
28+
.toMatchTypeOf<Expect>()
29+
})
30+
31+
it('should extend TypeError', () => {
32+
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatible>()
33+
.toMatchTypeOf<TypeError>()
34+
})
35+
})
36+
37+
describe('ErrImportAttributeTypeIncompatibleConstructor', () => {
38+
it('should match NodeErrorConstructor', () => {
39+
// Arrange
40+
type T = TestSubject.ErrImportAttributeTypeIncompatible
41+
type Args = TestSubject.ErrImportAttributeTypeIncompatibleArgs
42+
43+
// Expect
44+
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatibleConstructor>()
45+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
46+
})
47+
})
48+
})
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @file Errors - ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
3+
* @module errnode/errors/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
4+
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1342-L1343
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_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_import_attribute_type_incompatible
16+
*
17+
* @extends {NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrImportAttributeTypeIncompatible
21+
extends NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>, TypeError {}
22+
23+
/**
24+
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` message arguments.
25+
*/
26+
type Args = [id: string, type: string]
27+
28+
/**
29+
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` constructor.
30+
*
31+
* @see {@linkcode Args}
32+
* @see {@linkcode ErrImportAttributeTypeIncompatible}
33+
* @see {@linkcode NodeErrorConstructor}
34+
*
35+
* @extends {NodeErrorConstructor<ErrImportAttributeTypeIncompatible,Args>}
36+
*/
37+
interface ErrImportAttributeTypeIncompatibleConstructor
38+
extends NodeErrorConstructor<ErrImportAttributeTypeIncompatible, Args> {
39+
/**
40+
* Create a new `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` error.
41+
*
42+
* @see {@linkcode ErrImportAttributeTypeIncompatible}
43+
*
44+
* @param {string} id
45+
* Module id
46+
* @param {string} type
47+
* Specified type
48+
* @return {ErrImportAttributeTypeIncompatible}
49+
*/
50+
new (id: string, type: string): ErrImportAttributeTypeIncompatible
51+
}
52+
53+
/**
54+
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` model.
55+
*
56+
* Thrown when an import `type` attribute is provided, but the specified module
57+
* is of a different type.
58+
*
59+
* @see {@linkcode ErrImportAttributeTypeIncompatibleConstructor}
60+
*
61+
* @type {ErrImportAttributeTypeIncompatibleConstructor}
62+
*
63+
* @class
64+
*/
65+
const ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE:
66+
ErrImportAttributeTypeIncompatibleConstructor = E(
67+
codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
68+
TypeError,
69+
'Module "%s" is not of type "%s"'
70+
)
71+
72+
export {
73+
ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE as default,
74+
type ErrImportAttributeTypeIncompatible,
75+
type Args as ErrImportAttributeTypeIncompatibleArgs,
76+
type ErrImportAttributeTypeIncompatibleConstructor
77+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export {
3434
type ErrImportAttributeMissingArgs,
3535
type ErrImportAttributeMissingConstructor
3636
} from './err-import-attribute-missing'
37+
export {
38+
default as ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
39+
type ErrImportAttributeTypeIncompatible,
40+
type ErrImportAttributeTypeIncompatibleArgs,
41+
type ErrImportAttributeTypeIncompatibleConstructor
42+
} from './err-import-attribute-type-incompatible'
3743
export {
3844
default as ERR_INCOMPATIBLE_OPTION_PAIR,
3945
type ErrIncompatibleOptionPair,

0 commit comments

Comments
 (0)