Skip to content

Commit 2302af2

Browse files
committed
feat(errors): ERR_UNSUPPORTED_RESOLVE_REQUEST
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent be10dec commit 2302af2

7 files changed

+141
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ This package exports the following identifiers:
168168
- `ERR_UNKNOWN_MODULE_FORMAT`
169169
- `ERR_UNSUPPORTED_DIR_IMPORT`
170170
- `ERR_UNSUPPORTED_ESM_URL_SCHEME`
171+
- `ERR_UNSUPPORTED_RESOLVE_REQUEST`
171172
- [`formatList`](#formatlistlist-type)
172173
- [`hideStackFrames`](#hidestackframesfn)
173174
- [`isNodeError`](#isnodeerrorvalue)

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ exports[`integration:errors > ERR_UNKNOWN_MODULE_FORMAT > #toString > should ret
4949
exports[`integration:errors > ERR_UNSUPPORTED_DIR_IMPORT > #toString > should return string representation of error 1`] = `Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '../errors' is not supported resolving ES modules imported from file://\${process.cwd()}/src/__tests__/errors.integration.spec.ts`;
5050

5151
exports[`integration:errors > ERR_UNSUPPORTED_ESM_URL_SCHEME > #toString > should return string representation of error 1`] = `Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: data, file, and node are supported by the default ESM loader. Received protocol 'https:'`;
52+
53+
exports[`integration:errors > ERR_UNSUPPORTED_RESOLVE_REQUEST > #toString > should return string representation of error 1`] = `TypeError [ERR_UNSUPPORTED_RESOLVE_REQUEST]: Failed to resolve module specifier "not-found" from "data:text/javascript,export default import.meta.resolve('not-found')": Invalid relative URL or base scheme is not hierarchical.`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
3030
"ERR_UNKNOWN_MODULE_FORMAT",
3131
"ERR_UNSUPPORTED_DIR_IMPORT",
3232
"ERR_UNSUPPORTED_ESM_URL_SCHEME",
33+
"ERR_UNSUPPORTED_RESOLVE_REQUEST",
3334
"errors",
3435
"determineSpecificType",
3536
"formatList",

src/__tests__/errors.integration.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ describe('integration:errors', () => {
106106
Error,
107107
new URL('unist-util-visit', 'https://esm.sh/@flex-development/'),
108108
['data', 'file', 'node']
109+
],
110+
[
111+
codes.ERR_UNSUPPORTED_RESOLVE_REQUEST,
112+
TypeError,
113+
'not-found',
114+
'data:text/javascript,export default import.meta.resolve(\'not-found\')'
109115
]
110116
])('%s', (code, Base, ...args) => {
111117
let subject: NodeError
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - ERR_UNSUPPORTED_RESOLVE_REQUEST
3+
* @module errnode/errors/tests/unit-d/ERR_UNSUPPORTED_RESOLVE_REQUEST
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-unsupported-resolve-request'
9+
10+
describe('unit-d:errors/ERR_UNSUPPORTED_RESOLVE_REQUEST', () => {
11+
describe('ERR_UNSUPPORTED_RESOLVE_REQUEST', () => {
12+
it('should be ErrUnsupportedResolveRequestConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrUnsupportedResolveRequestConstructor>()
15+
})
16+
})
17+
18+
describe('ErrUnsupportedResolveRequest', () => {
19+
it('should extend NodeError<codes.ERR_UNSUPPORTED_RESOLVE_REQUEST>', () => {
20+
expectTypeOf<TestSubject.ErrUnsupportedResolveRequest>()
21+
.toMatchTypeOf<NodeError<codes.ERR_UNSUPPORTED_RESOLVE_REQUEST>>()
22+
})
23+
24+
it('should extend TypeError', () => {
25+
expectTypeOf<TestSubject.ErrUnsupportedResolveRequest>()
26+
.toMatchTypeOf<TypeError>()
27+
})
28+
})
29+
30+
describe('ErrUnsupportedResolveRequestConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrUnsupportedResolveRequest
34+
type Args = TestSubject.ErrUnsupportedResolveRequestArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrUnsupportedResolveRequestConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @file Errors - ERR_UNSUPPORTED_RESOLVE_REQUEST
3+
* @module errnode/errors/ERR_UNSUPPORTED_RESOLVE_REQUEST
4+
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1839-L1841
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_UNSUPPORTED_RESOLVE_REQUEST` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_unsupported_resolve_request
16+
*
17+
* @extends {NodeError<codes.ERR_UNSUPPORTED_RESOLVE_REQUEST>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrUnsupportedResolveRequest
21+
extends NodeError<codes.ERR_UNSUPPORTED_RESOLVE_REQUEST>, TypeError {}
22+
23+
/**
24+
* `ERR_UNSUPPORTED_RESOLVE_REQUEST` message arguments.
25+
*/
26+
type Args = [specifier: string, base: URL | string]
27+
28+
/**
29+
* `ERR_UNSUPPORTED_RESOLVE_REQUEST` constructor.
30+
*
31+
* @see {@linkcode Args}
32+
* @see {@linkcode ErrUnsupportedResolveRequest}
33+
* @see {@linkcode NodeErrorConstructor}
34+
*
35+
* @extends {NodeErrorConstructor<ErrUnsupportedResolveRequest,Args>}
36+
*/
37+
interface ErrUnsupportedResolveRequestConstructor
38+
extends NodeErrorConstructor<ErrUnsupportedResolveRequest, Args> {
39+
/**
40+
* Create a new `ERR_UNSUPPORTED_RESOLVE_REQUEST` error.
41+
*
42+
* @see {@linkcode ErrUnsupportedResolveRequest}
43+
*
44+
* @param {string} specifier
45+
* The module specifier that failed to resolve
46+
* @param {URL | string} base
47+
* Parent module id
48+
* @return {ErrUnsupportedResolveRequest}
49+
*/
50+
new (specifier: string, base: URL | string): ErrUnsupportedResolveRequest
51+
}
52+
53+
/**
54+
* `ERR_UNSUPPORTED_RESOLVE_REQUEST` model.
55+
*
56+
* Thrown when an attempt is made to resolve an invalid module referrer. This
57+
* can happen when importing or calling `import.meta.resolve()` with either:
58+
* - a bare specifier that is not a builtin module from a module whose URL
59+
* scheme is not file.
60+
* - a [relative URL][relative-url] from a module whose URL scheme is not a
61+
* [special scheme][special-scheme].
62+
*
63+
* [relative-url]: https://url.spec.whatwg.org/#relative-url-string
64+
* [special-scheme]: https://url.spec.whatwg.org/#special-scheme
65+
*
66+
* @see {@linkcode ErrUnsupportedResolveRequestConstructor}
67+
*
68+
* @type {ErrUnsupportedResolveRequestConstructor}
69+
*
70+
* @class
71+
*/
72+
const ERR_UNSUPPORTED_RESOLVE_REQUEST: ErrUnsupportedResolveRequestConstructor =
73+
E(
74+
codes.ERR_UNSUPPORTED_RESOLVE_REQUEST,
75+
TypeError,
76+
'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.'
77+
)
78+
79+
export {
80+
ERR_UNSUPPORTED_RESOLVE_REQUEST as default,
81+
type ErrUnsupportedResolveRequest,
82+
type Args as ErrUnsupportedResolveRequestArgs,
83+
type ErrUnsupportedResolveRequestConstructor
84+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,9 @@ export {
154154
type ErrUnsupportedEsmUrlSchemeArgs,
155155
type ErrUnsupportedEsmUrlSchemeConstructor
156156
} from './err-unsupported-esm-url-scheme'
157+
export {
158+
default as ERR_UNSUPPORTED_RESOLVE_REQUEST,
159+
type ErrUnsupportedResolveRequest,
160+
type ErrUnsupportedResolveRequestArgs,
161+
type ErrUnsupportedResolveRequestConstructor
162+
} from './err-unsupported-resolve-request'

0 commit comments

Comments
 (0)