Skip to content

Commit 960252f

Browse files
committed
quic: use less specific error codes
Stop the madness. Only you can prevent excessive error code proliferation.
1 parent 99f0404 commit 960252f

13 files changed

+138
-260
lines changed

doc/api/errors.md

Lines changed: 19 additions & 112 deletions
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

@@ -1732,125 +1742,13 @@ Accessing `Object.prototype.__proto__` has been forbidden using
17321742
[`Object.setPrototypeOf`][] should be used to get and set the prototype of an
17331743
object.
17341744

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

17941748
> Stability: 1 - Experimental
17951749
17961750
TBD
17971751

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

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

2383+
<a id="ERR_OPERATION_FAILED"></a>
2384+
### `ERR_OPERATION_FAILED`
2385+
<!-- YAML
2386+
added: REPLACEME
2387+
-->
2388+
2389+
An operation failed. This is typically used to signal the general failure
2390+
of an asynchronous operation.
2391+
24852392
<a id="ERR_OUTOFMEMORY"></a>
24862393
### `ERR_OUTOFMEMORY`
24872394
<!-- YAML

doc/api/quic.md

Lines changed: 1 addition & 1 deletion
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

lib/internal/errors.js

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
11921192
return `Expected ${input} to be returned from the "${name}"` +
11931193
` function but got ${type}.`;
11941194
}, TypeError);
1195+
E('ERR_INVALID_STATE', 'Invalid state: %s', Error);
11951196
E('ERR_INVALID_SYNC_FORK_INPUT',
11961197
'Asynchronous forks do not support ' +
11971198
'Buffer, TypedArray, DataView or string input: %s',
@@ -1287,6 +1288,7 @@ E('ERR_NO_CRYPTO',
12871288
'Node.js is not compiled with OpenSSL crypto support', Error);
12881289
E('ERR_NO_ICU',
12891290
'%s is not supported on Node.js compiled without ICU', TypeError);
1291+
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error);
12901292
E('ERR_OUT_OF_RANGE',
12911293
(str, range, input, replaceDefaultBoolean = false) => {
12921294
assert(range, 'Missing "range" argument');
@@ -1317,61 +1319,13 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
13171319
return `Package subpath '${subpath}' is not defined by "exports" in ${
13181320
pkgPath} imported from ${base}`;
13191321
}, Error);
1320-
E('ERR_QUICCLIENTSESSION_FAILED',
1321-
'Failed to create a new QuicClientSession: %s', Error);
1322-
E('ERR_QUICCLIENTSESSION_FAILED_SETSOCKET',
1323-
'Failed to set the QuicSocket', Error);
1324-
E('ERR_QUICSESSION_DESTROYED',
1325-
'Cannot call %s after a QuicSession has been destroyed', Error);
1326-
E('ERR_QUICSESSION_INVALID_DCID', 'Invalid DCID value: %s', Error);
1327-
E('ERR_QUICSESSION_UPDATEKEY', 'Unable to update QuicSession keys', Error);
13281322
E('ERR_QUICSESSION_VERSION_NEGOTIATION',
13291323
(version, requestedVersions, supportedVersions) => {
13301324
return 'QUIC session received version negotiation from server. ' +
13311325
`Version: ${version}. Requested: ${requestedVersions.join(', ')} ` +
13321326
`Supported: ${supportedVersions.join(', ')}`;
13331327
},
13341328
Error);
1335-
E('ERR_QUICSOCKET_DESTROYED',
1336-
'Cannot call %s after a QuicSocket has been destroyed', Error);
1337-
E('ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH',
1338-
'The stateResetToken must be exactly 16-bytes in length',
1339-
Error);
1340-
E('ERR_QUICSOCKET_LISTENING',
1341-
'This QuicSocket is already listening', Error);
1342-
E('ERR_QUICSOCKET_UNBOUND',
1343-
'Cannot call %s before a QuicSocket has been bound', Error);
1344-
E('ERR_QUICSTREAM_DESTROYED',
1345-
'Cannot call %s after a QuicStream has been destroyed', Error);
1346-
E('ERR_QUICSTREAM_INVALID_PUSH',
1347-
'Push streams are only supported on client-initiated, bidirectional streams',
1348-
Error);
1349-
E('ERR_QUICSTREAM_OPEN_FAILED', 'Opening a new QuicStream failed', Error);
1350-
E('ERR_QUICSTREAM_UNSUPPORTED_PUSH',
1351-
'Push streams are not supported on this QuicSession', Error);
1352-
E('ERR_QUIC_ERROR', function(code, family) {
1353-
const {
1354-
constants: {
1355-
QUIC_ERROR_APPLICATION,
1356-
QUIC_ERROR_CRYPTO,
1357-
QUIC_ERROR_SESSION,
1358-
}
1359-
} = internalBinding('quic');
1360-
let familyType = 'unknown';
1361-
switch (family) {
1362-
case QUIC_ERROR_APPLICATION:
1363-
familyType = 'application';
1364-
break;
1365-
case QUIC_ERROR_CRYPTO:
1366-
familyType = 'crypto';
1367-
break;
1368-
case QUIC_ERROR_SESSION:
1369-
familyType = 'session';
1370-
break;
1371-
}
1372-
return `QUIC session closed with ${familyType} error code ${code}`;
1373-
}, Error);
1374-
E('ERR_QUIC_TLS13_REQUIRED', 'QUIC requires TLS version 1.3', Error);
13751329
E('ERR_REQUIRE_ESM',
13761330
(filename, parentPath = null, packageJsonPath = null) => {
13771331
let msg = `Must use import to load ES Module: ${filename}`;

0 commit comments

Comments
 (0)