Skip to content

Commit 5e769b2

Browse files
committed
quic: use less specific error codes
Stop the madness. Only you can prevent excessive error code proliferation. PR-URL: #34262 Reviewed-By: Anna Henningsen <[email protected]>
1 parent d36e832 commit 5e769b2

13 files changed

+138
-260
lines changed

Diff for: doc/api/errors.md

+19-112
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,16 @@ type for one of its returned object properties on execution.
14401440
Thrown in case a function option does not return an expected value
14411441
type on execution, such as when a function is expected to return a promise.
14421442

1443+
<a id="ERR_INVALID_STATE"></a>
1444+
### `ERR_INVALID_STATE`
1445+
<!-- YAML
1446+
added: REPLACEME
1447+
-->
1448+
1449+
Indicates that an operation cannot be completed due to an invalid state.
1450+
For instance, an object may have already been destroyed, or may be
1451+
performing another operation.
1452+
14431453
<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
14441454
### `ERR_INVALID_SYNC_FORK_INPUT`
14451455

@@ -1738,125 +1748,13 @@ Accessing `Object.prototype.__proto__` has been forbidden using
17381748
[`Object.setPrototypeOf`][] should be used to get and set the prototype of an
17391749
object.
17401750

1741-
<a id="ERR_QUIC_CANNOT_SET_GROUPS"></a>
1742-
### `ERR_QUIC_CANNOT_SET_GROUPS`
1743-
1744-
> Stability: 1 - Experimental
1745-
1746-
TBD
1747-
1748-
<a id="ERR_QUIC_ERROR"></a>
1749-
### `ERR_QUIC_ERROR`
1750-
1751-
> Stability: 1 - Experimental
1752-
1753-
TBD
1754-
1755-
<a id="ERR_QUIC_TLS13_REQUIRED"></a>
1756-
### `ERR_QUIC_TLS13_REQUIRED`
1757-
1758-
> Stability: 1 - Experimental
1759-
1760-
TBD
1761-
1762-
<a id="ERR_QUICCLIENTSESSION_FAILED"></a>
1763-
### `ERR_QUICCLIENTSESSION_FAILED`
1764-
1765-
> Stability: 1 - Experimental
1766-
1767-
TBD
1768-
1769-
<a id="ERR_QUICCLIENTSESSION_FAILED_SETSOCKET"></a>
1770-
### `ERR_QUICCLIENTSESSION_FAILED_SETSOCKET`
1771-
1772-
> Stability: 1 - Experimental
1773-
1774-
TBD
1775-
1776-
<a id="ERR_QUICSESSION_DESTROYED"></a>
1777-
### `ERR_QUICSESSION_DESTROYED`
1778-
1779-
> Stability: 1 - Experimental
1780-
1781-
TBD
1782-
1783-
<a id="ERR_QUICSESSION_INVALID_DCID"></a>
1784-
### `ERR_QUICSESSION_INVALID_DCID`
1785-
1786-
> Stability: 1 - Experimental
1787-
1788-
TBD
1789-
1790-
<a id="ERR_QUICSESSION_UPDATEKEY"></a>
1791-
### `ERR_QUICSESSION_UPDATEKEY`
1792-
1793-
> Stability: 1 - Experimental
1794-
1795-
TBD
1796-
17971751
<a id="ERR_QUICSESSION_VERSION_NEGOTIATION"></a>
17981752
### `ERR_QUICSESSION_VERSION_NEGOTIATION`
17991753

18001754
> Stability: 1 - Experimental
18011755
18021756
TBD
18031757

1804-
<a id="ERR_QUICSOCKET_DESTROYED"></a>
1805-
### `ERR_QUICSOCKET_DESTROYED`
1806-
1807-
> Stability: 1 - Experimental
1808-
1809-
TBD
1810-
1811-
<a id="ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH"></a>
1812-
### `ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH`
1813-
1814-
> Stability: 1 - Experimental
1815-
1816-
TBD
1817-
1818-
<a id="ERR_QUICSOCKET_LISTENING"></a>
1819-
### `ERR_QUICSOCKET_LISTENING`
1820-
1821-
> Stability: 1 - Experimental
1822-
1823-
TBD
1824-
1825-
<a id="ERR_QUICSOCKET_UNBOUND"></a>
1826-
### `ERR_QUICSOCKET_UNBOUND`
1827-
1828-
> Stability: 1 - Experimental
1829-
1830-
TBD
1831-
1832-
<a id="ERR_QUICSTREAM_DESTROYED"></a>
1833-
### `ERR_QUICSTREAM_DESTROYED`
1834-
1835-
> Stability: 1 - Experimental
1836-
1837-
TBD
1838-
1839-
<a id="ERR_QUICSTREAM_INVALID_PUSH"></a>
1840-
### `ERR_QUICSTREAM_INVALID_PUSH`
1841-
1842-
> Stability: 1 - Experimental
1843-
1844-
TBD
1845-
1846-
<a id="ERR_QUICSTREAM_OPEN_FAILED"></a>
1847-
### `ERR_QUICSTREAM_OPEN_FAILED`
1848-
1849-
> Stability: 1 - Experimental
1850-
1851-
TBD
1852-
1853-
<a id="ERR_QUICSTREAM_UNSUPPORTED_PUSH"></a>
1854-
### `ERR_QUICSTREAM_UNSUPPORTED_PUSH`
1855-
1856-
> Stability: 1 - Experimental
1857-
1858-
TBD
1859-
18601758
<a id="ERR_REQUIRE_ESM"></a>
18611759
### `ERR_REQUIRE_ESM`
18621760

@@ -2488,6 +2386,15 @@ Used by the `N-API` when `Constructor.prototype` is not an object.
24882386
A Node.js API was called in an unsupported manner, such as
24892387
`Buffer.write(string, encoding, offset[, length])`.
24902388

2389+
<a id="ERR_OPERATION_FAILED"></a>
2390+
### `ERR_OPERATION_FAILED`
2391+
<!-- YAML
2392+
added: REPLACEME
2393+
-->
2394+
2395+
An operation failed. This is typically used to signal the general failure
2396+
of an asynchronous operation.
2397+
24912398
<a id="ERR_OUTOFMEMORY"></a>
24922399
### `ERR_OUTOFMEMORY`
24932400
<!-- YAML

Diff for: doc/api/quic.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ Migrates the `QuicClientSession` to the given `QuicSocket` instance. If the new
12501250
`QuicSocket` has not yet been bound to a local UDP port, it will be bound prior
12511251
to attempting the migration. If the `QuicClientSession` is not yet ready to
12521252
migrate, the callback will be invoked with an `Error` using the code
1253-
`ERR_QUICCLIENTSESSION_FAILED_SETSOCKET`.
1253+
`ERR_OPERATION_FAILED`.
12541254

12551255
### Class: QuicServerSession extends QuicSession
12561256
<!-- YAML

Diff for: lib/internal/errors.js

+2-48
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,7 @@ E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
11731173
return `Expected ${input} to be returned from the "${name}"` +
11741174
` function but got ${type}.`;
11751175
}, TypeError);
1176+
E('ERR_INVALID_STATE', 'Invalid state: %s', Error);
11761177
E('ERR_INVALID_SYNC_FORK_INPUT',
11771178
'Asynchronous forks do not support ' +
11781179
'Buffer, TypedArray, DataView or string input: %s',
@@ -1268,6 +1269,7 @@ E('ERR_NO_CRYPTO',
12681269
'Node.js is not compiled with OpenSSL crypto support', Error);
12691270
E('ERR_NO_ICU',
12701271
'%s is not supported on Node.js compiled without ICU', TypeError);
1272+
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error);
12711273
E('ERR_OUT_OF_RANGE',
12721274
(str, range, input, replaceDefaultBoolean = false) => {
12731275
assert(range, 'Missing "range" argument');
@@ -1299,61 +1301,13 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
12991301
return `Package subpath '${subpath}' is not defined by "exports" in ${
13001302
pkgPath}package.json${base ? ` imported from ${base}` : ''}`;
13011303
}, Error);
1302-
E('ERR_QUICCLIENTSESSION_FAILED',
1303-
'Failed to create a new QuicClientSession: %s', Error);
1304-
E('ERR_QUICCLIENTSESSION_FAILED_SETSOCKET',
1305-
'Failed to set the QuicSocket', Error);
1306-
E('ERR_QUICSESSION_DESTROYED',
1307-
'Cannot call %s after a QuicSession has been destroyed', Error);
1308-
E('ERR_QUICSESSION_INVALID_DCID', 'Invalid DCID value: %s', Error);
1309-
E('ERR_QUICSESSION_UPDATEKEY', 'Unable to update QuicSession keys', Error);
13101304
E('ERR_QUICSESSION_VERSION_NEGOTIATION',
13111305
(version, requestedVersions, supportedVersions) => {
13121306
return 'QUIC session received version negotiation from server. ' +
13131307
`Version: ${version}. Requested: ${requestedVersions.join(', ')} ` +
13141308
`Supported: ${supportedVersions.join(', ')}`;
13151309
},
13161310
Error);
1317-
E('ERR_QUICSOCKET_DESTROYED',
1318-
'Cannot call %s after a QuicSocket has been destroyed', Error);
1319-
E('ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH',
1320-
'The stateResetToken must be exactly 16-bytes in length',
1321-
Error);
1322-
E('ERR_QUICSOCKET_LISTENING',
1323-
'This QuicSocket is already listening', Error);
1324-
E('ERR_QUICSOCKET_UNBOUND',
1325-
'Cannot call %s before a QuicSocket has been bound', Error);
1326-
E('ERR_QUICSTREAM_DESTROYED',
1327-
'Cannot call %s after a QuicStream has been destroyed', Error);
1328-
E('ERR_QUICSTREAM_INVALID_PUSH',
1329-
'Push streams are only supported on client-initiated, bidirectional streams',
1330-
Error);
1331-
E('ERR_QUICSTREAM_OPEN_FAILED', 'Opening a new QuicStream failed', Error);
1332-
E('ERR_QUICSTREAM_UNSUPPORTED_PUSH',
1333-
'Push streams are not supported on this QuicSession', Error);
1334-
E('ERR_QUIC_ERROR', function(code, family) {
1335-
const {
1336-
constants: {
1337-
QUIC_ERROR_APPLICATION,
1338-
QUIC_ERROR_CRYPTO,
1339-
QUIC_ERROR_SESSION,
1340-
}
1341-
} = internalBinding('quic');
1342-
let familyType = 'unknown';
1343-
switch (family) {
1344-
case QUIC_ERROR_APPLICATION:
1345-
familyType = 'application';
1346-
break;
1347-
case QUIC_ERROR_CRYPTO:
1348-
familyType = 'crypto';
1349-
break;
1350-
case QUIC_ERROR_SESSION:
1351-
familyType = 'session';
1352-
break;
1353-
}
1354-
return `QUIC session closed with ${familyType} error code ${code}`;
1355-
}, Error);
1356-
E('ERR_QUIC_TLS13_REQUIRED', 'QUIC requires TLS version 1.3', Error);
13571311
E('ERR_REQUIRE_ESM',
13581312
(filename, parentPath = null, packageJsonPath = null) => {
13591313
let msg = `Must use import to load ES Module: ${filename}`;

0 commit comments

Comments
 (0)