GeezerVison is showing github.com — esm: rename error code related to import attributes · nodejs/node@7740bf8
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/errors.md +45-20Lines changed: 45 additions & 20 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1749,43 +1749,29 @@ is set for the `Http2Stream`. | 1749 | 1749 |
| 1750 | 1750 | An attempt was made to construct an object using a non-public constructor. | 1751 | 1751 |
| 1752 | | -<a id="ERR_IMPORT_ASSERTION_TYPE_FAILED"></a> | | 1752 | +<a id="ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE"></a> | 1753 | 1753 |
| 1754 | | -### `ERR_IMPORT_ASSERTION_TYPE_FAILED` | | 1754 | +### `ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE` | 1755 | 1755 |
| 1756 | 1756 | <!-- YAML | 1757 | 1757 | added: | 1758 | | - - v17.1.0 | 1759 | | - - v16.14.0 | | 1758 | + - REPLACEME | 1760 | 1759 | --> | 1761 | 1760 |
| 1762 | 1761 | An import `type` attribute was provided, but the specified module is of a | 1763 | 1762 | different type. | 1764 | 1763 |
| 1765 | | -<a id="ERR_IMPORT_ASSERTION_TYPE_MISSING"></a> | | 1764 | +<a id="ERR_IMPORT_ATTRIBUTE_MISSING"></a> | 1766 | 1765 |
| 1767 | | -### `ERR_IMPORT_ASSERTION_TYPE_MISSING` | | 1766 | +### `ERR_IMPORT_ATTRIBUTE_MISSING` | 1768 | 1767 |
| 1769 | 1768 | <!-- YAML | 1770 | 1769 | added: | 1771 | | - - v17.1.0 | 1772 | | - - v16.14.0 | | 1770 | + - REPLACEME | 1773 | 1771 | --> | 1774 | 1772 |
| 1775 | 1773 | An import attribute is missing, preventing the specified module to be imported. | 1776 | 1774 |
| 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 | | - | 1789 | 1775 | <a id="ERR_IMPORT_ATTRIBUTE_UNSUPPORTED"></a> | 1790 | 1776 |
| 1791 | 1777 | ### `ERR_IMPORT_ATTRIBUTE_UNSUPPORTED` | @@ -3308,6 +3294,45 @@ changes: | 3308 | 3294 |
| 3309 | 3295 | An invalid transfer object was passed to `postMessage()`. | 3310 | 3296 |
| | 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 | + | 3311 | 3336 | <a id="ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST"></a> | 3312 | 3337 |
| 3313 | 3338 | ### `ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST` | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/errors.js +3-8Lines changed: 3 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1280,15 +1280,10 @@ E('ERR_HTTP_SOCKET_ENCODING', | 1280 | 1280 | E('ERR_HTTP_TRAILER_INVALID', | 1281 | 1281 | 'Trailers are invalid with this transfer encoding', Error); | 1282 | 1282 | 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', | 1285 | 1286 | '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); | 1292 | 1287 | E('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', | 1293 | 1288 | 'Import attribute "%s" with value "%s" is not supported', TypeError); | 1294 | 1289 | E('ERR_INCOMPATIBLE_OPTION_PAIR', | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/assert.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,9 +10,8 @@ const { | 10 | 10 | const { validateString } = require('internal/validators'); | 11 | 11 |
| 12 | 12 | 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, | 16 | 15 | ERR_IMPORT_ATTRIBUTE_UNSUPPORTED, | 17 | 16 | } = require('internal/errors').codes; | 18 | 17 |
| @@ -86,7 +85,7 @@ function validateAttributes(url, format, | 86 | 85 | // `importAttributes.type` might not have been it. | 87 | 86 | if (!ObjectPrototypeHasOwnProperty(importAttributes, 'type')) { | 88 | 87 | // `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); | 90 | 89 | } | 91 | 90 | return handleInvalidType(url, importAttributes.type); | 92 | 91 | } | @@ -103,11 +102,11 @@ function handleInvalidType(url, type) { | 103 | 102 |
| 104 | 103 | // `type` might not have been one of the types we understand. | 105 | 104 | if (!ArrayPrototypeIncludes(supportedAssertionTypes, type)) { | 106 | | - throw new ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED(type); | | 105 | + throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type); | 107 | 106 | } | 108 | 107 |
| 109 | 108 | // `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); | 111 | 110 | } | 112 | 111 |
| 113 | 112 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-attributes-errors.js +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,37 +18,37 @@ async function test() { | 18 | 18 |
| 19 | 19 | await rejects( | 20 | 20 | 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' } | 22 | 22 | ); | 23 | 23 |
| 24 | 24 | await rejects( | 25 | 25 | import(jsModuleDataUrl, { with: { type: 'json' } }), | 26 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } | | 26 | + { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | 27 | 27 | ); | 28 | 28 |
| 29 | 29 | await rejects( | 30 | 30 | import(jsModuleDataUrl, { with: { type: 'unsupported' } }), | 31 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | | 31 | + { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | 32 | 32 | ); | 33 | 33 |
| 34 | 34 | await rejects( | 35 | 35 | import(jsonModuleDataUrl), | 36 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 36 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 37 | 37 | ); | 38 | 38 |
| 39 | 39 | await rejects( | 40 | 40 | import(jsonModuleDataUrl, { with: {} }), | 41 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 41 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 42 | 42 | ); | 43 | 43 |
| 44 | 44 | await rejects( | 45 | 45 | import(jsonModuleDataUrl, { with: { foo: 'bar' } }), | 46 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 46 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 47 | 47 | ); | 48 | 48 |
| 49 | 49 | await rejects( | 50 | 50 | import(jsonModuleDataUrl, { with: { type: 'unsupported' } }), | 51 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | | 51 | + { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | 52 | 52 | ); | 53 | 53 | } | 54 | 54 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-attributes-errors.mjs +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,35 +13,35 @@ await rejects( | 13 | 13 |
| 14 | 14 | await rejects( | 15 | 15 | 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' } | 17 | 17 | ); | 18 | 18 |
| 19 | 19 | await rejects( | 20 | 20 | import(jsModuleDataUrl, { with: { type: 'json' } }), | 21 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' } | | 21 | + { code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE' } | 22 | 22 | ); | 23 | 23 |
| 24 | 24 | await rejects( | 25 | 25 | import(import.meta.url, { with: { type: 'unsupported' } }), | 26 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | | 26 | + { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | 27 | 27 | ); | 28 | 28 |
| 29 | 29 | await rejects( | 30 | 30 | import(jsonModuleDataUrl), | 31 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 31 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 32 | 32 | ); | 33 | 33 |
| 34 | 34 | await rejects( | 35 | 35 | import(jsonModuleDataUrl, { with: {} }), | 36 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 36 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 37 | 37 | ); | 38 | 38 |
| 39 | 39 | await rejects( | 40 | 40 | import(jsonModuleDataUrl, { with: { foo: 'bar' } }), | 41 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' } | | 41 | + { code: 'ERR_IMPORT_ATTRIBUTE_MISSING' } | 42 | 42 | ); | 43 | 43 |
| 44 | 44 | await rejects( | 45 | 45 | import(jsonModuleDataUrl, { with: { type: 'unsupported' } }), | 46 | | - { code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' } | | 46 | + { code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED' } | 47 | 47 | ); |
Collapse file Copy file name to clipboardExpand all lines: test/es-module/test-esm-import-attributes-validation.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ assert.ok(validateAttributes(url, 'module', {})); | 15 | 15 | assert.ok(validateAttributes(url, 'wasm', {})); | 16 | 16 |
| 17 | 17 | assert.throws(() => validateAttributes(url, 'json', {}), { | 18 | | - code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING', | | 18 | + code: 'ERR_IMPORT_ATTRIBUTE_MISSING', | 19 | 19 | }); | 20 | 20 |
| 21 | 21 | assert.throws(() => validateAttributes(url, 'json', { type: 'json', unsupportedAttribute: 'value' }), { | @@ -27,17 +27,17 @@ assert.throws(() => validateAttributes(url, 'module', { unsupportedAttribute: 'v | 27 | 27 | }); | 28 | 28 |
| 29 | 29 | assert.throws(() => validateAttributes(url, 'module', { type: 'json' }), { | 30 | | - code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED', | | 30 | + code: 'ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE', | 31 | 31 | }); | 32 | 32 |
| 33 | 33 | // The HTML spec specifically disallows this for now, while Wasm module import | 34 | 34 | // and whether it will require a type assertion is still an open question. | 35 | 35 | assert.throws(() => validateAttributes(url, 'module', { type: 'javascript' }), { | 36 | | - code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED', | | 36 | + code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', | 37 | 37 | }); | 38 | 38 |
| 39 | 39 | assert.throws(() => validateAttributes(url, 'module', { type: 'css' }), { | 40 | | - code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED', | | 40 | + code: 'ERR_IMPORT_ATTRIBUTE_UNSUPPORTED', | 41 | 41 | }); | 42 | 42 |
| 43 | 43 | assert.throws(() => validateAttributes(url, 'module', { type: false }), { | |
|