Skip to content

Commit a48f6b0

Browse files
committed
feat(errors): ERR_INVALID_FILE_URL_PATH
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 632c79a commit a48f6b0

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ This package exports the following identifiers:
155155
- `ERR_INVALID_ARG_TYPE`
156156
- `ERR_INVALID_ARG_VALUE`
157157
- `ERR_INVALID_FILE_URL_HOST`
158+
- `ERR_INVALID_FILE_URL_PATH`
158159
- `ERR_INVALID_MODULE_SPECIFIER`
159160
- `ERR_INVALID_PACKAGE_CONFIG`
160161
- `ERR_INVALID_PACKAGE_TARGET`

src/__snapshots__/errors.integration.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ exports[`integration:errors > ERR_INVALID_ARG_VALUE > #toString > should return
2424

2525
exports[`integration:errors > ERR_INVALID_FILE_URL_HOST > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_FILE_URL_HOST]: File URL host must be "localhost" or empty on darwin`;
2626

27+
exports[`integration:errors > ERR_INVALID_FILE_URL_PATH > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must not include encoded \\ or / characters`;
28+
2729
exports[`integration:errors > ERR_INVALID_MODULE_SPECIFIER > #toString > should return string representation of error 1`] = `TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module '@flex-development%2Fpathe' is not a valid package name imported from \${process.cwd()}/scratch.ts`;
2830

2931
exports[`integration:errors > ERR_INVALID_PACKAGE_CONFIG > #toString > should return string representation of error 1`] = `Error [ERR_INVALID_PACKAGE_CONFIG]: Invalid package config \${process.cwd()}/node_modules/@flex-development/pathe/package.json while importing file://\${process.cwd()}/loader.mjs. "exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`;

src/__snapshots__/index.e2e.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ exports[`e2e:errnode > should expose public api 1`] = `
1717
"ERR_INVALID_ARG_TYPE",
1818
"ERR_INVALID_ARG_VALUE",
1919
"ERR_INVALID_FILE_URL_HOST",
20+
"ERR_INVALID_FILE_URL_PATH",
2021
"ERR_INVALID_MODULE_SPECIFIER",
2122
"ERR_INVALID_PACKAGE_CONFIG",
2223
"ERR_INVALID_PACKAGE_TARGET",

src/__tests__/errors.integration.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ describe('integration:errors', () => {
5454
[codes.ERR_INVALID_ARG_TYPE, TypeError, 'ctor', 'Function', null],
5555
[codes.ERR_INVALID_ARG_VALUE, TypeError, 'address', 1],
5656
[codes.ERR_INVALID_FILE_URL_HOST, TypeError, 'darwin'],
57+
[
58+
codes.ERR_INVALID_FILE_URL_PATH,
59+
TypeError,
60+
'must not include encoded \\ or / characters'
61+
],
5762
[
5863
codes.ERR_INVALID_MODULE_SPECIFIER,
5964
TypeError,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @file Type Tests - ERR_INVALID_FILE_URL_PATH
3+
* @module errnode/errors/tests/unit-d/ERR_INVALID_FILE_URL_PATH
4+
*/
5+
6+
import { codes } from '#src/enums'
7+
import type { NodeError, NodeErrorConstructor } from '#src/interfaces'
8+
import type * as TestSubject from '../err-invalid-file-url-path'
9+
10+
describe('unit-d:errors/ERR_INVALID_FILE_URL_PATH', () => {
11+
describe('ERR_INVALID_FILE_URL_PATH', () => {
12+
it('should be ErrInvalidFileUrlPathConstructor', () => {
13+
expectTypeOf<typeof TestSubject.default>()
14+
.toEqualTypeOf<TestSubject.ErrInvalidFileUrlPathConstructor>()
15+
})
16+
})
17+
18+
describe('ErrInvalidFileUrlPath', () => {
19+
it('should extend NodeError<codes.ERR_INVALID_FILE_URL_PATH>', () => {
20+
expectTypeOf<TestSubject.ErrInvalidFileUrlPath>()
21+
.toMatchTypeOf<NodeError<codes.ERR_INVALID_FILE_URL_PATH>>()
22+
})
23+
24+
it('should extend TypeError', () => {
25+
expectTypeOf<TestSubject.ErrInvalidFileUrlPath>()
26+
.toMatchTypeOf<TypeError>()
27+
})
28+
})
29+
30+
describe('ErrInvalidFileUrlPathConstructor', () => {
31+
it('should match NodeErrorConstructor', () => {
32+
// Arrange
33+
type T = TestSubject.ErrInvalidFileUrlPath
34+
type Args = TestSubject.ErrInvalidFileUrlPathArgs
35+
36+
// Expect
37+
expectTypeOf<TestSubject.ErrInvalidFileUrlPathConstructor>()
38+
.toMatchTypeOf<NodeErrorConstructor<T, Args>>()
39+
})
40+
})
41+
})
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @file Errors - ERR_INVALID_FILE_URL_PATH
3+
* @module errnode/errors/ERR_INVALID_FILE_URL_PATH
4+
* @see https://github.com/nodejs/node/blob/v22.8.0/lib/internal/errors.js#L1472
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_INVALID_FILE_URL_PATH` schema.
13+
*
14+
* @see {@linkcode NodeError}
15+
* @see https://nodejs.org/api/errors.html#err_invalid_file_url_path
16+
*
17+
* @extends {NodeError<codes.ERR_INVALID_FILE_URL_PATH>}
18+
* @extends {TypeError}
19+
*/
20+
interface ErrInvalidFileUrlPath
21+
extends NodeError<codes.ERR_INVALID_FILE_URL_PATH>, TypeError {}
22+
23+
/**
24+
* `ERR_INVALID_FILE_URL_PATH` message arguments.
25+
*/
26+
type Args = [reason: string]
27+
28+
/**
29+
* `ERR_INVALID_FILE_URL_PATH` constructor.
30+
*
31+
* @see {@linkcode ErrInvalidFileUrlPath}
32+
* @see {@linkcode NodeErrorConstructor}
33+
*
34+
* @extends {NodeErrorConstructor<ErrInvalidFileUrlPath,Args>}
35+
*/
36+
interface ErrInvalidFileUrlPathConstructor
37+
extends NodeErrorConstructor<ErrInvalidFileUrlPath, Args> {
38+
/**
39+
* Create a new `ERR_INVALID_FILE_URL_PATH` error.
40+
*
41+
* @see {@linkcode ErrInvalidFileUrlPath}
42+
*
43+
* @param {string} reason
44+
* Reason for invalidity
45+
* @return {ErrInvalidFileUrlPath}
46+
*/
47+
new (reason: string): ErrInvalidFileUrlPath
48+
}
49+
50+
/**
51+
* `ERR_INVALID_FILE_URL_PATH` model.
52+
*
53+
* Thrown when a Node.js API that consumes `file:` URLs encountered a file URL
54+
* with an incompatible path.
55+
* The exact semantics for determining whether a path can be used is
56+
* platform-dependent.
57+
*
58+
* @see {@linkcode ErrInvalidFileUrlPathConstructor}
59+
*
60+
* @type {ErrInvalidFileUrlPathConstructor}
61+
*
62+
* @class
63+
*/
64+
const ERR_INVALID_FILE_URL_PATH: ErrInvalidFileUrlPathConstructor = E(
65+
codes.ERR_INVALID_FILE_URL_PATH,
66+
TypeError,
67+
'File URL path %s'
68+
)
69+
70+
export {
71+
ERR_INVALID_FILE_URL_PATH as default,
72+
type ErrInvalidFileUrlPath,
73+
type Args as ErrInvalidFileUrlPathArgs,
74+
type ErrInvalidFileUrlPathConstructor
75+
}

src/errors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export {
7676
type ErrInvalidFileUrlHostArgs,
7777
type ErrInvalidFileUrlHostConstructor
7878
} from './err-invalid-file-url-host'
79+
export {
80+
default as ERR_INVALID_FILE_URL_PATH,
81+
type ErrInvalidFileUrlPath,
82+
type ErrInvalidFileUrlPathArgs,
83+
type ErrInvalidFileUrlPathConstructor
84+
} from './err-invalid-file-url-path'
7985
export {
8086
default as ERR_INVALID_MODULE_SPECIFIER,
8187
type ErrInvalidModuleSpecifier,

0 commit comments

Comments
 (0)