Skip to content

Commit

Permalink
feat(errors): ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Aug 26, 2024
1 parent cb549e9 commit c6305f8
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ This package exports the following identifiers:
- `ERR_IMPORT_ASSERTION_TYPE_MISSING`
- `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`
- `ERR_IMPORT_ATTRIBUTE_MISSING`
- `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE`
- `ERR_INCOMPATIBLE_OPTION_PAIR`
- `ERR_INVALID_ARG_TYPE`
- `ERR_INVALID_ARG_VALUE`
Expand Down
13 changes: 13 additions & 0 deletions __fixtures__/js-module-data-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file Fixtures - JS_MODULE_DATA_URL
* @module fixtures/JS_MODULE_DATA_URL
*/

/**
* JavaScript module `data:` URL.
*
* @const {string} JS_MODULE_DATA_URL
*/
const JS_MODULE_DATA_URL: string = 'data:text/javascript,export{}'

export default JS_MODULE_DATA_URL
2 changes: 2 additions & 0 deletions src/__snapshots__/errors.integration.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exports[`integration:errors > ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED > #toString

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"`;

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"`;

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

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`;
Expand Down
1 change: 1 addition & 0 deletions src/__snapshots__/index.e2e.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
"ERR_IMPORT_ASSERTION_TYPE_MISSING",
"ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED",
"ERR_IMPORT_ATTRIBUTE_MISSING",
"ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE",
"ERR_INCOMPATIBLE_OPTION_PAIR",
"ERR_INVALID_ARG_TYPE",
"ERR_INVALID_ARG_VALUE",
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/errors.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @module errnode/tests/integration/errors
*/

import JS_MODULE_DATA_URL from '#fixtures/js-module-data-url'
import JSON_MODULE_DATA_URL from '#fixtures/json-module-data-url'
import { codes, syscodes } from '#src/enums'
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
Expand Down Expand Up @@ -41,6 +42,12 @@ describe('integration:errors', () => {
'type',
'json'
],
[
codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
TypeError,
JS_MODULE_DATA_URL,
'json'
],
[codes.ERR_INCOMPATIBLE_OPTION_PAIR, TypeError, 'N', 'cost'],
[codes.ERR_INVALID_ARG_TYPE, TypeError, 'ctor', 'Function', null],
[codes.ERR_INVALID_ARG_VALUE, TypeError, 'address', 1],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file Type Tests - ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
* @module errnode/errors/tests/unit-d/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
*/

import { codes } from '#src/enums'
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
import type * as TestSubject from '../err-import-attribute-type-incompatible'

describe('unit-d:errors/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE', () => {
describe('ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE', () => {
it('should be ErrImportAttributeTypeIncompatibleConstructor', () => {
// Arrange
type Expect = TestSubject.ErrImportAttributeTypeIncompatibleConstructor

// Expect
expectTypeOf<typeof TestSubject.default>().toEqualTypeOf<Expect>()
})
})

describe('ErrImportAttributeTypeIncompatible', () => {
it('should extend NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>', () => {
// Arrange
type Expect = NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>

// Expect
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatible>()
.toMatchTypeOf<Expect>()
})

it('should extend TypeError', () => {
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatible>()
.toMatchTypeOf<TypeError>()
})
})

describe('ErrImportAttributeTypeIncompatibleConstructor', () => {
it('should match NodeErrorConstructor', () => {
// Arrange
type T = TestSubject.ErrImportAttributeTypeIncompatible
type Args = TestSubject.ErrImportAttributeTypeIncompatibleArgs

// Expect
expectTypeOf<TestSubject.ErrImportAttributeTypeIncompatibleConstructor>()
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
})
})
})
77 changes: 77 additions & 0 deletions src/errors/err-import-attribute-type-incompatible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @file Errors - ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
* @module errnode/errors/ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1342-L1343
*/

import E from '#e'
import { codes } from '#src/enums'
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'

/**
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` schema.
*
* @see {@linkcode NodeError}
* @see https://nodejs.org/api/errors.html#err_import_attribute_type_incompatible
*
* @extends {NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>}
* @extends {TypeError}
*/
interface ErrImportAttributeTypeIncompatible
extends NodeError<codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE>, TypeError {}

/**
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` message arguments.
*/
type Args = [id: string, type: string]

/**
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` constructor.
*
* @see {@linkcode Args}
* @see {@linkcode ErrImportAttributeTypeIncompatible}
* @see {@linkcode NodeErrorConstructor}
*
* @extends {NodeErrorConstructor<ErrImportAttributeTypeIncompatible,Args>}
*/
interface ErrImportAttributeTypeIncompatibleConstructor
extends NodeErrorConstructor<ErrImportAttributeTypeIncompatible, Args> {
/**
* Create a new `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` error.
*
* @see {@linkcode ErrImportAttributeTypeIncompatible}
*
* @param {string} id
* Module id
* @param {string} type
* Specified type
* @return {ErrImportAttributeTypeIncompatible}
*/
new (id: string, type: string): ErrImportAttributeTypeIncompatible
}

/**
* `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` model.
*
* Thrown when an import `type` attribute is provided, but the specified module
* is of a different type.
*
* @see {@linkcode ErrImportAttributeTypeIncompatibleConstructor}
*
* @type {ErrImportAttributeTypeIncompatibleConstructor}
*
* @class
*/
const ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE:
ErrImportAttributeTypeIncompatibleConstructor = E(
codes.ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
TypeError,
'Module "%s" is not of type "%s"'
)

export {
ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE as default,
type ErrImportAttributeTypeIncompatible,
type Args as ErrImportAttributeTypeIncompatibleArgs,
type ErrImportAttributeTypeIncompatibleConstructor
}
6 changes: 6 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export {
type ErrImportAttributeMissingArgs,
type ErrImportAttributeMissingConstructor
} from './err-import-attribute-missing'
export {
default as ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
type ErrImportAttributeTypeIncompatible,
type ErrImportAttributeTypeIncompatibleArgs,
type ErrImportAttributeTypeIncompatibleConstructor
} from './err-import-attribute-type-incompatible'
export {
default as ERR_INCOMPATIBLE_OPTION_PAIR,
type ErrIncompatibleOptionPair,
Expand Down

0 comments on commit c6305f8

Please sign in to comment.