Skip to content

Commit b16995c

Browse files
committed
feat(models): ERR_UNKNOWN_BUILTIN_MODULE
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 0a0d256 commit b16995c

File tree

4 files changed

+96
-14
lines changed

4 files changed

+96
-14
lines changed

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Universal API for creating [Node.js errors][1]
4141
- [`ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, base[, dir])`](#err_package_import_not_definedspecifier-base-dir)
4242
- [`ERR_PACKAGE_PATH_NOT_EXPORTED(dir, subpath[, base])`](#err_package_path_not_exporteddir-subpath-base)
4343
- [`ERR_UNHANDLED_ERROR([err])`](#err_unhandled_errorerr)
44+
- [`ERR_UNKNOWN_BUILTIN_MODULE(name)`](#err_unknown_builtin_modulename)
4445
- [`ERR_UNKNOWN_ENCODING(encoding)`](#err_unknown_encodingencoding)
4546
- [`ERR_UNKNOWN_FILE_EXTENSION(ext, id[, suggestion])`](#err_unknown_file_extensionext-id-suggestion)
4647
- [`ERR_UNKNOWN_MODULE_FORMAT(format, id)`](#err_unknown_module_formatformat-id)
@@ -226,6 +227,7 @@ This package exports the following identifiers:
226227
- [`ERR_PACKAGE_IMPORT_NOT_DEFINED`](#err_package_import_not_definedspecifier-base-dir)
227228
- [`ERR_PACKAGE_PATH_NOT_EXPORTED`](#err_package_path_not_exporteddir-subpath-base)
228229
- [`ERR_UNHANDLED_ERROR`](#err_unhandled_errorerr)
230+
- [`ERR_UNKNOWN_BUILTIN_MODULE`](#err_unknown_builtin_modulename)
229231
- [`ERR_UNKNOWN_ENCODING`](#err_unknown_encodingencoding)
230232
- [`ERR_UNKNOWN_FILE_EXTENSION`](#err_unknown_file_extensionext-id-suggestion)
231233
- [`ERR_UNKNOWN_MODULE_FORMAT`](#err_unknown_module_formatformat-id)
@@ -387,7 +389,7 @@ Thrown when a [`package.json`][8] file fails parsing.
387389
- `{string}` **`id`** &mdash; Location of invalid `package.json` file
388390
- `{string?}` **`[base='']`** &mdash; Id of module being imported. May also include where module is being imported from
389391
- `{string?}` **`[reason='']`** &mdash; Reason package config is invalid
390-
- **Returns**: `{NodeError<Error>}`
392+
- **Returns**: `{NodeError}`
391393

392394
> **Source**: [`src/models/err-invalid-package-config.ts`](src/models/err-invalid-package-config.ts)
393395
@@ -401,7 +403,7 @@ the attempted module resolution.
401403
- `{unknown}` **`target`** &mdash; Invalid package target
402404
- `{boolean?}` **`[internal=false]`** &mdash; `target` is `"imports"`?
403405
- `{string?}` **`[base='']`** &mdash; Id of module `package.json` was imported from
404-
- **Returns**: `{NodeError<Error>}`
406+
- **Returns**: `{NodeError}`
405407

406408
> **Source**: [`src/models/err-invalid-package-target.ts`](src/models/err-invalid-package-target.ts)
407409
@@ -419,7 +421,7 @@ Thrown when an invalid URL is passed to a [WHATWG][11] [`URL` constructor][12] o
419421
Thrown when a method is required but not implemented.
420422

421423
- `{string}` **`method`** &mdash; Method name
422-
- **Returns**: `{NodeError<Error>}`
424+
- **Returns**: `{NodeError}`
423425

424426
> **Source**: [`src/models/err-method-not-implemented.ts`](src/models/err-method-not-implemented.ts)
425427
@@ -440,7 +442,7 @@ when loading a program entry point.
440442
- `{string}` **`id`** &mdash; Id of missing module
441443
- `{string}` **`base`** &mdash; Id of module `id` was imported from
442444
- `{string?}` **`[type='package']`** &mdash; Module file type
443-
- **Returns**: `{NodeError<Error>}`
445+
- **Returns**: `{NodeError}`
444446

445447
> **Source**: [`src/models/err-module-not-found.ts`](src/models/err-module-not-found.ts)
446448
@@ -451,7 +453,7 @@ Thrown when a network module attempts to load another module that it is not allo
451453
- `{string}` **`specifier`** &mdash; Invalid module specifier
452454
- `{string}` **`base`** &mdash; Id of module `specifier` was imported from
453455
- `{string}` **`reason`** &mdash; Reason for error
454-
- **Returns**: `{NodeError<Error>}`
456+
- **Returns**: `{NodeError}`
455457

456458
> **Source**: [`src/models/err-network-import-disallowed.ts`](src/models/err-network-import-disallowed.ts)
457459
@@ -460,7 +462,7 @@ Thrown when a network module attempts to load another module that it is not allo
460462
Thrown when an operation has failed. Typically used to signal the general failure of an asynchronous operation.
461463

462464
- `{string}` **`reason`** &mdash; Reason for operation failure
463-
- **Returns**: `{NodeError<Error>}`
465+
- **Returns**: `{NodeError}`
464466

465467
> **Source**: [`src/models/err-operation-failed.ts`](src/models/err-operation-failed.ts)
466468
@@ -482,7 +484,7 @@ Thrown when a `package.json` [`"exports"`][9] field does not export the requeste
482484
- `{string}` **`dir`** &mdash; Id of directory containing `package.json`
483485
- `{string}` **`subpath`** &mdash; Requested subpath
484486
- `{string?}` **`[base='']`** &mdash; Id of module `subpath` was imported from
485-
- **Returns**: `{NodeError<Error>}`
487+
- **Returns**: `{NodeError}`
486488

487489
> **Source**: [`src/models/err-package-path-not-exported.ts`](src/models/err-package-path-not-exported.ts)
488490
@@ -491,10 +493,19 @@ Thrown when a `package.json` [`"exports"`][9] field does not export the requeste
491493
Thrown when an unhandled error occurs.
492494

493495
- `{string?}` **`[err='']`** &mdash; Stringified error
494-
- **Returns**: `{NodeError<Error>}`
496+
- **Returns**: `{NodeError}`
495497

496498
> **Source**: [`src/models/err-unhandled-error.ts`](src/models/err-unhandled-error.ts)
497499
500+
#### `ERR_UNKNOWN_BUILTIN_MODULE(name)`
501+
502+
Thrown when an unknown [builtin module][14] is encountered.
503+
504+
- `{string}` **`name`** &mdash; Module name
505+
- **Returns**: `{NodeError}`
506+
507+
> **Source**: [`src/models/err-unknown-builtin-module.ts`](src/models/err-unknown-builtin-module.ts)
508+
498509
#### `ERR_UNKNOWN_ENCODING(encoding)`
499510

500511
Thrown when an invalid or unknown encoding option is passed to a Node.js API.
@@ -531,7 +542,7 @@ Thrown when a directory URL is `import`ed.
531542

532543
- `{string}` **`id`** &mdash; Module id of directory
533544
- `{string}` **`base`** &mdash; Id of module `id` was imported from
534-
- **Returns**: `{NodeError<Error>}`
545+
- **Returns**: `{NodeError}`
535546

536547
> **Source**: [`src/models/err-unsupported-dir-import.ts`](src/models/err-unsupported-dir-import.ts)
537548
@@ -542,7 +553,7 @@ Thrown when an unsupported URL scheme is used in an `import` statement. URL sche
542553
- `{URL}` **`url`** &mdash; URL containing unsupported scheme
543554
- `{string[]}` **`supported`** &mdash; Supported URL schemes
544555
- `{boolean?}` **`[windows=false]`** &mdash; Windows operating system?
545-
- **Returns**: `{NodeError<Error>}`
556+
- **Returns**: `{NodeError}`
546557

547558
> **Source**: [`src/models/err-unsupported-esm-url-scheme.ts`](src/models/err-unsupported-esm-url-scheme.ts)
548559
@@ -553,7 +564,7 @@ Thrown when an unsupported URL scheme is used in an `import` statement. URL sche
553564
Creates a Node.js error constructor.
554565

555566
If the given error `message` is a function, constructor arguments are passed to `message`. If the `message` is a string,
556-
constructor arguments are passed to [`util.format`][14] instead.
567+
constructor arguments are passed to [`util.format`][15] instead.
557568

558569
- `{ErrorCode}` **`code`** &mdash; Node.js error code
559570
- `{B extends ErrorConstructor}` **`Base`** &mdash; Error base class
@@ -573,7 +584,7 @@ Determines the specific type of a value for type-mismatch errors.
573584
574585
## Types
575586

576-
This package is fully typed with [TypeScript][15]. It exports the following definitions:
587+
This package is fully typed with [TypeScript][16]. It exports the following definitions:
577588

578589
### Enums
579590

@@ -608,5 +619,6 @@ See [`CONTRIBUTING.md`](CONTRIBUTING.md).
608619
[11]: https://nodejs.org/api/url.html#the-whatwg-url-api
609620
[12]: https://nodejs.org/api/url.html#new-urlinput-base
610621
[13]: https://nodejs.org/api/url.html#urlparseurlstring-parsequerystring-slashesdenotehost
611-
[14]: https://nodejs.org/api/util.html#utilformatformat-args
612-
[15]: https://www.typescriptlang.org
622+
[14]: https://nodejs.org/api/module.html#modulebuiltinmodules
623+
[15]: https://nodejs.org/api/util.html#utilformatformat-args
624+
[16]: https://www.typescriptlang.org
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file Unit Tests - ERR_UNKNOWN_BUILTIN_MODULE
3+
* @module errnode/models/tests/unit/ERR_UNKNOWN_BUILTIN_MODULE
4+
*/
5+
6+
import { ErrorCode } from '#src/enums'
7+
import type { NodeError } from '#src/types'
8+
import TestSubject from '../err-unknown-builtin-module'
9+
10+
describe('unit:models/ERR_UNKNOWN_BUILTIN_MODULE', () => {
11+
let name: string
12+
let result: NodeError
13+
14+
beforeEach(() => {
15+
name = 'node:foo'
16+
result = new TestSubject(name)
17+
})
18+
19+
it('should return Error instance', () => {
20+
expect(result).to.be.instanceof(Error)
21+
expect(result).to.have.property('name').equal('Error')
22+
})
23+
24+
it('should set error code', () => {
25+
expect(result)
26+
.to.have.property('code')
27+
.equal(ErrorCode.ERR_UNKNOWN_BUILTIN_MODULE)
28+
})
29+
30+
it('should set error message', () => {
31+
expect(result)
32+
.to.have.property('message')
33+
.equal(`No such built-in module: ${name}`)
34+
})
35+
})
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @file Error Models - ERR_UNKNOWN_BUILTIN_MODULE
3+
* @module errnode/models/ERR_UNKNOWN_BUILTIN_MODULE
4+
* @see https://github.com/nodejs/node/blob/v19.3.0/lib/internal/errors.js#L1683
5+
*/
6+
7+
import { ErrorCode } from '#src/enums'
8+
import type { NodeError, NodeErrorConstructor } from '#src/types'
9+
import { createNodeError } from '#src/utils'
10+
11+
/**
12+
* `ERR_UNKNOWN_BUILTIN_MODULE` model.
13+
*
14+
* Thrown when an unknown [builtin module][1] is encountered.
15+
*
16+
* [1]: https://nodejs.org/api/module.html#modulebuiltinmodules
17+
*
18+
* @see https://nodejs.org/api/errors.html#err_unknown_builtin_module
19+
*
20+
* @class
21+
*
22+
* @param {string} name - Module name
23+
* @return {NodeError} `Error` instance
24+
*/
25+
const ERR_UNKNOWN_BUILTIN_MODULE: NodeErrorConstructor<
26+
ErrorConstructor,
27+
[string]
28+
> = createNodeError(
29+
ErrorCode.ERR_UNKNOWN_BUILTIN_MODULE,
30+
Error,
31+
'No such built-in module: %s'
32+
)
33+
34+
export default ERR_UNKNOWN_BUILTIN_MODULE

src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export { default as ERR_OPERATION_FAILED } from './err-operation-failed'
2626
export { default as ERR_PACKAGE_IMPORT_NOT_DEFINED } from './err-package-import-not-defined'
2727
export { default as ERR_PACKAGE_PATH_NOT_EXPORTED } from './err-package-path-not-exported'
2828
export { default as ERR_UNHANDLED_ERROR } from './err-unhandled-error'
29+
export { default as ERR_UNKNOWN_BUILTIN_MODULE } from './err-unknown-builtin-module'
2930
export { default as ERR_UNKNOWN_ENCODING } from './err-unknown-encoding'
3031
export { default as ERR_UNKNOWN_FILE_EXTENSION } from './err-unknown-file-extension'
3132
export { default as ERR_UNKNOWN_MODULE_FORMAT } from './err-unknown-module-format'

0 commit comments

Comments
 (0)