Skip to content

Commit

Permalink
feat(errors): ERR_IMPORT_ATTRIBUTE_UNSUPPORTED
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 c6305f8 commit db87bd6
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions src/__snapshots__/errors.integration.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
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 @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/errors.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
41 changes: 41 additions & 0 deletions src/errors/__tests__/err-import-attribute-unsupported.spec-d.ts
Original file line number Diff line number Diff line change
@@ -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<typeof TestSubject.default>()
.toEqualTypeOf<TestSubject.ErrImportAttributeUnsupportedConstructor>()
})
})

describe('ErrImportAttributeUnsupported', () => {
it('should extend NodeError<codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED>', () => {
expectTypeOf<TestSubject.ErrImportAttributeUnsupported>()
.toMatchTypeOf<NodeError<codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED>>()
})

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

describe('ErrImportAttributeUnsupportedConstructor', () => {
it('should match NodeErrorConstructor', () => {
// Arrange
type T = TestSubject.ErrImportAttributeUnsupported
type Args = TestSubject.ErrImportAttributeUnsupportedArgs

// Expect
expectTypeOf<TestSubject.ErrImportAttributeUnsupportedConstructor>()
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
})
})
})
76 changes: 76 additions & 0 deletions src/errors/err-import-attribute-unsupported.ts
Original file line number Diff line number Diff line change
@@ -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<codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED>}
* @extends {TypeError}
*/
interface ErrImportAttributeUnsupported
extends NodeError<codes.ERR_IMPORT_ATTRIBUTE_UNSUPPORTED>, 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<ErrImportAttributeUnsupported,Args>}
*/
interface ErrImportAttributeUnsupportedConstructor
extends NodeErrorConstructor<ErrImportAttributeUnsupported, Args> {
/**
* 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
}
6 changes: 6 additions & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit db87bd6

Please sign in to comment.