diff --git a/README.md b/README.md index 65001bc6..d53676b9 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ This package exports the following identifiers: - `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED` - `ERR_IMPORT_ATTRIBUTE_MISSING` - `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` + - `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` - `ERR_INCOMPATIBLE_OPTION_PAIR` - `ERR_INVALID_ARG_TYPE` - `ERR_INVALID_ARG_VALUE` diff --git a/src/__snapshots__/errors.integration.snap b/src/__snapshots__/errors.integration.snap index 7224e8af..79b3b1ee 100644 --- a/src/__snapshots__/errors.integration.snap +++ b/src/__snapshots__/errors.integration.snap @@ -12,6 +12,8 @@ exports[`integration:errors > ERR_IMPORT_ATTRIBUTE_MISSING > #toString > should 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_IMPORT_ATTRIBUTE_UNSUPPORTED > #toString > should return string representation of error 1`] = `TypeError [ERR_IMPORT_ATTRIBUTE_UNSUPPORTED]: Import attribute "type" with value "unsupported" is not supported`; + 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`; diff --git a/src/__snapshots__/index.e2e.snap b/src/__snapshots__/index.e2e.snap index 0a9ec16d..0e0388f8 100644 --- a/src/__snapshots__/index.e2e.snap +++ b/src/__snapshots__/index.e2e.snap @@ -11,6 +11,7 @@ exports[`e2e:errnode > should expose public api 1`] = ` "ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED", "ERR_IMPORT_ATTRIBUTE_MISSING", "ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE", + "ERR_IMPORT_ATTRIBUTE_UNSUPPORTED", "ERR_INCOMPATIBLE_OPTION_PAIR", "ERR_INVALID_ARG_TYPE", "ERR_INVALID_ARG_VALUE", diff --git a/src/__tests__/errors.integration.spec.ts b/src/__tests__/errors.integration.spec.ts index 4fcfd691..fa4e469d 100644 --- a/src/__tests__/errors.integration.spec.ts +++ b/src/__tests__/errors.integration.spec.ts @@ -48,6 +48,7 @@ describe('integration:errors', () => { JS_MODULE_DATA_URL, 'json' ], + [codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED, TypeError, 'type', 'unsupported'], [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], diff --git a/src/errors/__tests__/err-import-attribute-unsupported.spec-d.ts b/src/errors/__tests__/err-import-attribute-unsupported.spec-d.ts new file mode 100644 index 00000000..906e7743 --- /dev/null +++ b/src/errors/__tests__/err-import-attribute-unsupported.spec-d.ts @@ -0,0 +1,41 @@ +/** + * @file Type Tests - ERR_IMPORT_ATTRIBUTE_UNSUPPORTED + * @module errnode/errors/tests/unit-d/ERR_IMPORT_ATTRIBUTE_UNSUPPORTED + */ + +import { codes } from '#src/enums' +import type { NodeError, NodeErrorConstructor } from '#src/interfaces' +import type * as TestSubject from '../err-import-attribute-unsupported' + +describe('unit-d:errors/ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', () => { + describe('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', () => { + it('should be ErrImportAttributeUnsupportedConstructor', () => { + expectTypeOf() + .toEqualTypeOf() + }) + }) + + describe('ErrImportAttributeUnsupported', () => { + it('should extend NodeError', () => { + expectTypeOf() + .toMatchTypeOf>() + }) + + it('should extend TypeError', () => { + expectTypeOf() + .toMatchTypeOf() + }) + }) + + describe('ErrImportAttributeUnsupportedConstructor', () => { + it('should match NodeErrorConstructor', () => { + // Arrange + type T = TestSubject.ErrImportAttributeUnsupported + type Args = TestSubject.ErrImportAttributeUnsupportedArgs + + // Expect + expectTypeOf() + .toMatchTypeOf>() + }) + }) +}) diff --git a/src/errors/err-import-attribute-unsupported.ts b/src/errors/err-import-attribute-unsupported.ts new file mode 100644 index 00000000..23a0e3b1 --- /dev/null +++ b/src/errors/err-import-attribute-unsupported.ts @@ -0,0 +1,76 @@ +/** + * @file Errors - ERR_IMPORT_ATTRIBUTE_UNSUPPORTED + * @module errnode/errors/ERR_IMPORT_ATTRIBUTE_UNSUPPORTED + * @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1344-L1345 + */ + +import E from '#e' +import { codes } from '#src/enums' +import type { NodeError, NodeErrorConstructor } from '#src/interfaces' + +/** + * `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` schema. + * + * @see {@linkcode NodeError} + * @see https://nodejs.org/api/errors.html#err_import_attribute_unsupported + * + * @extends {NodeError} + * @extends {TypeError} + */ +interface ErrImportAttributeUnsupported + extends NodeError, TypeError {} + +/** + * `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` message arguments. + */ +type Args = [key: string, value: string] + +/** + * `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` constructor. + * + * @see {@linkcode Args} + * @see {@linkcode ErrImportAttributeUnsupported} + * @see {@linkcode NodeErrorConstructor} + * + * @extends {NodeErrorConstructor} + */ +interface ErrImportAttributeUnsupportedConstructor + extends NodeErrorConstructor { + /** + * Create a new `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` error. + * + * @see {@linkcode ErrImportAttributeUnsupported} + * + * @param {string} key + * Import attribute key + * @param {string} value + * Import attribute value + * @return {ErrImportAttributeUnsupported} + */ + new (key: string, value: string): ErrImportAttributeUnsupported +} + +/** + * `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` model. + * + * Thrown when an import attribute is not supported by a version of Node.js. + * + * @see {@linkcode ErrImportAttributeUnsupportedConstructor} + * + * @type {ErrImportAttributeUnsupportedConstructor} + * + * @class + */ +const ERR_IMPORT_ATTRIBUTE_UNSUPPORTED: + ErrImportAttributeUnsupportedConstructor = E( + codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED, + TypeError, + 'Import attribute "%s" with value "%s" is not supported' + ) + +export { + ERR_IMPORT_ATTRIBUTE_UNSUPPORTED as default, + type ErrImportAttributeUnsupported, + type Args as ErrImportAttributeUnsupportedArgs, + type ErrImportAttributeUnsupportedConstructor +} diff --git a/src/errors/index.ts b/src/errors/index.ts index 19da558f..5730adeb 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -40,6 +40,12 @@ export { type ErrImportAttributeTypeIncompatibleArgs, type ErrImportAttributeTypeIncompatibleConstructor } from './err-import-attribute-type-incompatible' +export { + default as ERR_IMPORT_ATTRIBUTE_UNSUPPORTED, + type ErrImportAttributeUnsupported, + type ErrImportAttributeUnsupportedArgs, + type ErrImportAttributeUnsupportedConstructor +} from './err-import-attribute-unsupported' export { default as ERR_INCOMPATIBLE_OPTION_PAIR, type ErrIncompatibleOptionPair,