Skip to content

Commit

Permalink
quic: use less specific error codes
Browse files Browse the repository at this point in the history
Stop the madness. Only you can prevent excessive error code
proliferation.
  • Loading branch information
jasnell committed Jul 9, 2020
1 parent 99f0404 commit 960252f
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 260 deletions.
131 changes: 19 additions & 112 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,16 @@ type for one of its returned object properties on execution.
Thrown in case a function option does not return an expected value
type on execution, such as when a function is expected to return a promise.

<a id="ERR_INVALID_STATE"></a>
### `ERR_INVALID_STATE`
<!-- YAML
added: REPLACEME
-->

Indicates that an operation cannot be completed due to an invalid state.
For instance, an object may have already been destroyed, or may be
performing another operation.

<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
### `ERR_INVALID_SYNC_FORK_INPUT`

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

<a id="ERR_QUIC_CANNOT_SET_GROUPS"></a>
### `ERR_QUIC_CANNOT_SET_GROUPS`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUIC_ERROR"></a>
### `ERR_QUIC_ERROR`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUIC_TLS13_REQUIRED"></a>
### `ERR_QUIC_TLS13_REQUIRED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICCLIENTSESSION_FAILED"></a>
### `ERR_QUICCLIENTSESSION_FAILED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICCLIENTSESSION_FAILED_SETSOCKET"></a>
### `ERR_QUICCLIENTSESSION_FAILED_SETSOCKET`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSESSION_DESTROYED"></a>
### `ERR_QUICSESSION_DESTROYED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSESSION_INVALID_DCID"></a>
### `ERR_QUICSESSION_INVALID_DCID`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSESSION_UPDATEKEY"></a>
### `ERR_QUICSESSION_UPDATEKEY`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSESSION_VERSION_NEGOTIATION"></a>
### `ERR_QUICSESSION_VERSION_NEGOTIATION`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSOCKET_DESTROYED"></a>
### `ERR_QUICSOCKET_DESTROYED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH"></a>
### `ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSOCKET_LISTENING"></a>
### `ERR_QUICSOCKET_LISTENING`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSOCKET_UNBOUND"></a>
### `ERR_QUICSOCKET_UNBOUND`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSTREAM_DESTROYED"></a>
### `ERR_QUICSTREAM_DESTROYED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSTREAM_INVALID_PUSH"></a>
### `ERR_QUICSTREAM_INVALID_PUSH`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSTREAM_OPEN_FAILED"></a>
### `ERR_QUICSTREAM_OPEN_FAILED`

> Stability: 1 - Experimental
TBD

<a id="ERR_QUICSTREAM_UNSUPPORTED_PUSH"></a>
### `ERR_QUICSTREAM_UNSUPPORTED_PUSH`

> Stability: 1 - Experimental
TBD

<a id="ERR_REQUIRE_ESM"></a>
### `ERR_REQUIRE_ESM`

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

<a id="ERR_OPERATION_FAILED"></a>
### `ERR_OPERATION_FAILED`
<!-- YAML
added: REPLACEME
-->

An operation failed. This is typically used to signal the general failure
of an asynchronous operation.

<a id="ERR_OUTOFMEMORY"></a>
### `ERR_OUTOFMEMORY`
<!-- YAML
Expand Down
2 changes: 1 addition & 1 deletion doc/api/quic.md
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ Migrates the `QuicClientSession` to the given `QuicSocket` instance. If the new
`QuicSocket` has not yet been bound to a local UDP port, it will be bound prior
to attempting the migration. If the `QuicClientSession` is not yet ready to
migrate, the callback will be invoked with an `Error` using the code
`ERR_QUICCLIENTSESSION_FAILED_SETSOCKET`.
`ERR_OPERATION_FAILED`.

### Class: QuicServerSession extends QuicSession
<!-- YAML
Expand Down
50 changes: 2 additions & 48 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
return `Expected ${input} to be returned from the "${name}"` +
` function but got ${type}.`;
}, TypeError);
E('ERR_INVALID_STATE', 'Invalid state: %s', Error);
E('ERR_INVALID_SYNC_FORK_INPUT',
'Asynchronous forks do not support ' +
'Buffer, TypedArray, DataView or string input: %s',
Expand Down Expand Up @@ -1287,6 +1288,7 @@ E('ERR_NO_CRYPTO',
'Node.js is not compiled with OpenSSL crypto support', Error);
E('ERR_NO_ICU',
'%s is not supported on Node.js compiled without ICU', TypeError);
E('ERR_OPERATION_FAILED', 'Operation failed: %s', Error);
E('ERR_OUT_OF_RANGE',
(str, range, input, replaceDefaultBoolean = false) => {
assert(range, 'Missing "range" argument');
Expand Down Expand Up @@ -1317,61 +1319,13 @@ E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
return `Package subpath '${subpath}' is not defined by "exports" in ${
pkgPath} imported from ${base}`;
}, Error);
E('ERR_QUICCLIENTSESSION_FAILED',
'Failed to create a new QuicClientSession: %s', Error);
E('ERR_QUICCLIENTSESSION_FAILED_SETSOCKET',
'Failed to set the QuicSocket', Error);
E('ERR_QUICSESSION_DESTROYED',
'Cannot call %s after a QuicSession has been destroyed', Error);
E('ERR_QUICSESSION_INVALID_DCID', 'Invalid DCID value: %s', Error);
E('ERR_QUICSESSION_UPDATEKEY', 'Unable to update QuicSession keys', Error);
E('ERR_QUICSESSION_VERSION_NEGOTIATION',
(version, requestedVersions, supportedVersions) => {
return 'QUIC session received version negotiation from server. ' +
`Version: ${version}. Requested: ${requestedVersions.join(', ')} ` +
`Supported: ${supportedVersions.join(', ')}`;
},
Error);
E('ERR_QUICSOCKET_DESTROYED',
'Cannot call %s after a QuicSocket has been destroyed', Error);
E('ERR_QUICSOCKET_INVALID_STATELESS_RESET_SECRET_LENGTH',
'The stateResetToken must be exactly 16-bytes in length',
Error);
E('ERR_QUICSOCKET_LISTENING',
'This QuicSocket is already listening', Error);
E('ERR_QUICSOCKET_UNBOUND',
'Cannot call %s before a QuicSocket has been bound', Error);
E('ERR_QUICSTREAM_DESTROYED',
'Cannot call %s after a QuicStream has been destroyed', Error);
E('ERR_QUICSTREAM_INVALID_PUSH',
'Push streams are only supported on client-initiated, bidirectional streams',
Error);
E('ERR_QUICSTREAM_OPEN_FAILED', 'Opening a new QuicStream failed', Error);
E('ERR_QUICSTREAM_UNSUPPORTED_PUSH',
'Push streams are not supported on this QuicSession', Error);
E('ERR_QUIC_ERROR', function(code, family) {
const {
constants: {
QUIC_ERROR_APPLICATION,
QUIC_ERROR_CRYPTO,
QUIC_ERROR_SESSION,
}
} = internalBinding('quic');
let familyType = 'unknown';
switch (family) {
case QUIC_ERROR_APPLICATION:
familyType = 'application';
break;
case QUIC_ERROR_CRYPTO:
familyType = 'crypto';
break;
case QUIC_ERROR_SESSION:
familyType = 'session';
break;
}
return `QUIC session closed with ${familyType} error code ${code}`;
}, Error);
E('ERR_QUIC_TLS13_REQUIRED', 'QUIC requires TLS version 1.3', Error);
E('ERR_REQUIRE_ESM',
(filename, parentPath = null, packageJsonPath = null) => {
let msg = `Must use import to load ES Module: ${filename}`;
Expand Down
Loading

0 comments on commit 960252f

Please sign in to comment.