Skip to content

Commit

Permalink
fix: cleaned up TMP errors
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
tegefaulkes committed Oct 4, 2023
1 parent 2198b56 commit 44609b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/nodes/NodeConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class NodeConnectionManager {
await Promise.all(destroyProms);
await this.quicServer.stop({ force: true });
await this.quicSocket.stop({ force: true });
await this.rpcServer?.destroy({ force: true, reason: Error('TMP NCM stopping')}); // TODO
await this.rpcServer?.destroy({ force: true, reason: new nodesErrors.ErrorNodeConnectionManagerStopping()});
this.logger.info(`Stopped ${this.constructor.name}`);
}

Expand Down Expand Up @@ -740,7 +740,7 @@ class NodeConnectionManager {
): Promise<Map<NodeIdString, ConnectionAndTimer>> {
const nodesEncoded = nodeIds.map((v) => nodesUtils.encodeNodeId(v));
this.logger.debug(`getting multi-connection for ${nodesEncoded}`);
if (nodeIds.length === 0) throw Error('TMP, must provide at least 1 node');
if (nodeIds.length === 0) throw new nodesErrors.ErrorNodeConnectionManagerNodeIdRequired();
const connectionsResults: Map<NodeIdString, ConnectionAndTimer> = new Map();
// 1. short circuit any existing connections
const nodesShortlist: Set<NodeIdString> = new Set();
Expand Down Expand Up @@ -816,9 +816,12 @@ class NodeConnectionManager {
await Promise.allSettled(connProms);
}
if (connectionsResults.size === 0) {
// TODO: This needs to throw if none were established.
// The usual use case is a single node, this shouldn't be a aggregate error type.
throw Error('TMP No connections established!');
throw new nodesErrors.ErrorNodeConnectionManagerMultiConnectionFailed(
undefined,
{
cause: new AggregateError(await Promise.allSettled(connProms))
}
);
}
return connectionsResults;
}
Expand Down Expand Up @@ -885,6 +888,8 @@ class NodeConnectionManager {
// 3. if already exists then clean up
await connection.destroy({ force: true });
// I can only see this happening as a race condition with creating a forward connection and receiving a reverse.
// FIXME: only here to see if this condition happens.
// this NEEDS to be removed, but I want to know if this branch happens at all.
throw Error(
'TMP IMP, This should be exceedingly rare, lets see if it happens',
);
Expand Down
18 changes: 18 additions & 0 deletions src/nodes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,26 @@ class ErrorNodeConnectionManagerNotRunning<T> extends ErrorNodeConnectionManager
exitCode = sysexits.USAGE;
}

class ErrorNodeConnectionManagerStopping<T> extends ErrorNodeConnectionManager<T> {
static description = 'NodeConnectionManager is stopping';
exitCode = sysexits.USAGE;
}

class ErrorNodeConnectionManagerInternalError<T> extends ErrorNodeConnectionManager<T> {
static description = 'There was an internal failure with NodeConnectionManager';
exitCode = sysexits.UNAVAILABLE;
}

class ErrorNodeConnectionManagerNodeIdRequired<T> extends ErrorNodeConnectionManager<T> {
static description = 'No NodeId was provided for establishing a multi connection';
exitCode = sysexits.USAGE;
}

class ErrorNodeConnectionManagerMultiConnectionFailed<T> extends ErrorNodeConnectionManager<T> {
static description = 'Failed to establish any connection during multi connection establishment';
exitCode = sysexits.TEMPFAIL;
}

class ErrorNodePingFailed<T> extends ErrorNodes<T> {
static description =
'Failed to ping the node when attempting to authenticate';
Expand Down Expand Up @@ -140,7 +155,10 @@ export {
ErrorNodeConnectionTransportGenericError,
ErrorNodeConnectionManager,
ErrorNodeConnectionManagerNotRunning,
ErrorNodeConnectionManagerStopping,
ErrorNodeConnectionManagerInternalError,
ErrorNodeConnectionManagerNodeIdRequired,
ErrorNodeConnectionManagerMultiConnectionFailed,
ErrorNodePingFailed,
ErrorNodePermissionDenied,
};

0 comments on commit 44609b9

Please sign in to comment.