Skip to content

Commit 7740bf8

Browse files
aduh95targos
authored andcommitted
esm: rename error code related to import attributes
PR-URL: #50181 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Zeyu "Alex" Yang <[email protected]>
1 parent 143ddde commit 7740bf8

File tree

6 files changed

+71
-52
lines changed

6 files changed

+71
-52
lines changed

doc/api/errors.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,43 +1749,29 @@ is set for the `Http2Stream`.
17491749

17501750
An attempt was made to construct an object using a non-public constructor.
17511751

1752-
<a id="ERR_IMPORT_ASSERTION_TYPE_FAILED"></a>
1752+
<a id="ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE"></a>
17531753

1754-
### `ERR_IMPORT_ASSERTION_TYPE_FAILED`
1754+
### `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE`
17551755

17561756
<!-- YAML
17571757
added:
1758-
- v17.1.0
1759-
- v16.14.0
1758+
- REPLACEME
17601759
-->
17611760

17621761
An import `type` attribute was provided, but the specified module is of a
17631762
different type.
17641763

1765-
<a id="ERR_IMPORT_ASSERTION_TYPE_MISSING"></a>
1764+
<a id="ERR_IMPORT_ATTRIBUTE_MISSING"></a>
17661765

1767-
### `ERR_IMPORT_ASSERTION_TYPE_MISSING`
1766+
### `ERR_IMPORT_ATTRIBUTE_MISSING`
17681767

17691768
<!-- YAML
17701769
added:
1771-
- v17.1.0
1772-
- v16.14.0
1770+
- REPLACEME
17731771
-->
17741772

17751773
An import attribute is missing, preventing the specified module to be imported.
17761774

1777-
<a id="ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED"></a>
1778-
1779-
### `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`
1780-
1781-
<!-- YAML
1782-
added:
1783-
- v17.1.0
1784-
- v16.14.0
1785-
-->
1786-
1787-
An import attribute is not supported by this version of Node.js.
1788-
17891775
<a id="ERR_IMPORT_ATTRIBUTE_UNSUPPORTED"></a>
17901776

17911777
### `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED`
@@ -3308,6 +3294,45 @@ changes:
33083294

33093295
An invalid transfer object was passed to `postMessage()`.
33103296

3297+
<a id="ERR_IMPORT_ASSERTION_TYPE_FAILED"></a>
3298+
3299+
### `ERR_IMPORT_ASSERTION_TYPE_FAILED`
3300+
3301+
<!-- YAML
3302+
added:
3303+
- v17.1.0
3304+
- v16.14.0
3305+
removed: REPLACEME
3306+
-->
3307+
3308+
An import assertion has failed, preventing the specified module to be imported.
3309+
3310+
<a id="ERR_IMPORT_ASSERTION_TYPE_MISSING"></a>
3311+
3312+
### `ERR_IMPORT_ASSERTION_TYPE_MISSING`
3313+
3314+
<!-- YAML
3315+
added:
3316+
- v17.1.0
3317+
- v16.14.0
3318+
removed: REPLACEME
3319+
-->
3320+
3321+
An import assertion is missing, preventing the specified module to be imported.
3322+
3323+
<a id="ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED"></a>
3324+
3325+
### `ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED`
3326+
3327+
<!-- YAML
3328+
added:
3329+
- v17.1.0
3330+
- v16.14.0
3331+
removed: REPLACEME
3332+
-->
3333+
3334+
An import attribute is not supported by this version of Node.js.
3335+
33113336
<a id="ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST"></a>
33123337

33133338
### `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST`

lib/internal/errors.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,15 +1280,10 @@ E('ERR_HTTP_SOCKET_ENCODING',
12801280
E('ERR_HTTP_TRAILER_INVALID',
12811281
'Trailers are invalid with this transfer encoding', Error);
12821282
E('ERR_ILLEGAL_CONSTRUCTOR', 'Illegal constructor', TypeError);
1283-
// TODO(aduh95): change the error to mention import attributes instead of import assertions.
1284-
E('ERR_IMPORT_ASSERTION_TYPE_FAILED',
1283+
E('ERR_IMPORT_ATTRIBUTE_MISSING',
1284+
'Module "%s" needs an import attribute of "%s: %s"', TypeError);
1285+
E('ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE',
12851286
'Module "%s" is not of type "%s"', TypeError);
1286-
// TODO(aduh95): change the error to mention import attributes instead of import assertions.
1287-
E('ERR_IMPORT_ASSERTION_TYPE_MISSING',
1288-
'Module "%s" needs an import attribute of type "%s"', TypeError);
1289-
// TODO(aduh95): change the error to mention import attributes instead of import assertions.
1290-
E('ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED',
1291-
'Import attribute type "%s" is unsupported', TypeError);
12921287
E('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
12931288
'Import attribute "%s" with value "%s" is not supported', TypeError);
12941289
E('ERR_INCOMPATIBLE_OPTION_PAIR',

lib/internal/modules/esm/assert.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ const {
1010
const { validateString } = require('internal/validators');
1111

1212
const {
13-
ERR_IMPORT_ASSERTION_TYPE_FAILED,
14-
ERR_IMPORT_ASSERTION_TYPE_MISSING,
15-
ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED,
13+
ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE,
14+
ERR_IMPORT_ATTRIBUTE_MISSING,
1615
ERR_IMPORT_ATTRIBUTE_UNSUPPORTED,
1716
} = require('internal/errors').codes;
1817

@@ -86,7 +85,7 @@ function validateAttributes(url, format,
8685
// `importAttributes.type` might not have been it.
8786
if (!ObjectPrototypeHasOwnProperty(importAttributes, 'type')) {
8887
// `type` wasn't specified at all.
89-
throw new ERR_IMPORT_ASSERTION_TYPE_MISSING(url, validType);
88+
throw new ERR_IMPORT_ATTRIBUTE_MISSING(url, 'type', validType);
9089
}
9190
return handleInvalidType(url, importAttributes.type);
9291
}
@@ -103,11 +102,11 @@ function handleInvalidType(url, type) {
103102

104103
// `type` might not have been one of the types we understand.
105104
if (!ArrayPrototypeIncludes(supportedAssertionTypes, type)) {
106-
throw new ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED(type);
105+
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type);
107106
}
108107

109108
// `type` was the wrong value for this format.
110-
throw new ERR_IMPORT_ASSERTION_TYPE_FAILED(url, type);
109+
throw new ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE(url, type);
111110
}
112111

113112

test/es-module/test-esm-import-attributes-errors.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@ async function test() {
1818

1919
await rejects(
2020
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`),
21-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
21+
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
2222
);
2323

2424
await rejects(
2525
import(jsModuleDataUrl, { with: { type: 'json' } }),
26-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
26+
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
2727
);
2828

2929
await rejects(
3030
import(jsModuleDataUrl, { with: { type: 'unsupported' } }),
31-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
31+
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
3232
);
3333

3434
await rejects(
3535
import(jsonModuleDataUrl),
36-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
36+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
3737
);
3838

3939
await rejects(
4040
import(jsonModuleDataUrl, { with: {} }),
41-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
41+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
4242
);
4343

4444
await rejects(
4545
import(jsonModuleDataUrl, { with: { foo: 'bar' } }),
46-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
46+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
4747
);
4848

4949
await rejects(
5050
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
51-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
51+
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
5252
);
5353
}
5454

test/es-module/test-esm-import-attributes-errors.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,35 @@ await rejects(
1313

1414
await rejects(
1515
import(`data:text/javascript,import${JSON.stringify(jsModuleDataUrl)}with{type:"json"}`),
16-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
16+
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
1717
);
1818

1919
await rejects(
2020
import(jsModuleDataUrl, { with: { type: 'json' } }),
21-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' }
21+
{ code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' }
2222
);
2323

2424
await rejects(
2525
import(import.meta.url, { with: { type: 'unsupported' } }),
26-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
26+
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
2727
);
2828

2929
await rejects(
3030
import(jsonModuleDataUrl),
31-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
31+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
3232
);
3333

3434
await rejects(
3535
import(jsonModuleDataUrl, { with: {} }),
36-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
36+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
3737
);
3838

3939
await rejects(
4040
import(jsonModuleDataUrl, { with: { foo: 'bar' } }),
41-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' }
41+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' }
4242
);
4343

4444
await rejects(
4545
import(jsonModuleDataUrl, { with: { type: 'unsupported' } }),
46-
{ code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' }
46+
{ code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' }
4747
);

test/es-module/test-esm-import-attributes-validation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ assert.ok(validateAttributes(url, 'module', {}));
1515
assert.ok(validateAttributes(url, 'wasm', {}));
1616

1717
assert.throws(() => validateAttributes(url, 'json', {}), {
18-
code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING',
18+
code: 'ERR_IMPORT_ATTRIBUTE_MISSING',
1919
});
2020

2121
assert.throws(() => validateAttributes(url, 'json', { type: 'json', unsupportedAttribute: 'value' }), {
@@ -27,17 +27,17 @@ assert.throws(() => validateAttributes(url, 'module', { unsupportedAttribute: 'v
2727
});
2828

2929
assert.throws(() => validateAttributes(url, 'module', { type: 'json' }), {
30-
code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED',
30+
code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE',
3131
});
3232

3333
// The HTML spec specifically disallows this for now, while Wasm module import
3434
// and whether it will require a type assertion is still an open question.
3535
assert.throws(() => validateAttributes(url, 'module', { type: 'javascript' }), {
36-
code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED',
36+
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
3737
});
3838

3939
assert.throws(() => validateAttributes(url, 'module', { type: 'css' }), {
40-
code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED',
40+
code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
4141
});
4242

4343
assert.throws(() => validateAttributes(url, 'module', { type: false }), {

0 commit comments

Comments
 (0)