Skip to content

Commit 44609b9

Browse files
committed
fix: cleaned up TMP errors
[ci skip]
1 parent 2198b56 commit 44609b9

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/nodes/NodeConnectionManager.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class NodeConnectionManager {
491491
await Promise.all(destroyProms);
492492
await this.quicServer.stop({ force: true });
493493
await this.quicSocket.stop({ force: true });
494-
await this.rpcServer?.destroy({ force: true, reason: Error('TMP NCM stopping')}); // TODO
494+
await this.rpcServer?.destroy({ force: true, reason: new nodesErrors.ErrorNodeConnectionManagerStopping()});
495495
this.logger.info(`Stopped ${this.constructor.name}`);
496496
}
497497

@@ -740,7 +740,7 @@ class NodeConnectionManager {
740740
): Promise<Map<NodeIdString, ConnectionAndTimer>> {
741741
const nodesEncoded = nodeIds.map((v) => nodesUtils.encodeNodeId(v));
742742
this.logger.debug(`getting multi-connection for ${nodesEncoded}`);
743-
if (nodeIds.length === 0) throw Error('TMP, must provide at least 1 node');
743+
if (nodeIds.length === 0) throw new nodesErrors.ErrorNodeConnectionManagerNodeIdRequired();
744744
const connectionsResults: Map<NodeIdString, ConnectionAndTimer> = new Map();
745745
// 1. short circuit any existing connections
746746
const nodesShortlist: Set<NodeIdString> = new Set();
@@ -816,9 +816,12 @@ class NodeConnectionManager {
816816
await Promise.allSettled(connProms);
817817
}
818818
if (connectionsResults.size === 0) {
819-
// TODO: This needs to throw if none were established.
820-
// The usual use case is a single node, this shouldn't be a aggregate error type.
821-
throw Error('TMP No connections established!');
819+
throw new nodesErrors.ErrorNodeConnectionManagerMultiConnectionFailed(
820+
undefined,
821+
{
822+
cause: new AggregateError(await Promise.allSettled(connProms))
823+
}
824+
);
822825
}
823826
return connectionsResults;
824827
}
@@ -885,6 +888,8 @@ class NodeConnectionManager {
885888
// 3. if already exists then clean up
886889
await connection.destroy({ force: true });
887890
// I can only see this happening as a race condition with creating a forward connection and receiving a reverse.
891+
// FIXME: only here to see if this condition happens.
892+
// this NEEDS to be removed, but I want to know if this branch happens at all.
888893
throw Error(
889894
'TMP IMP, This should be exceedingly rare, lets see if it happens',
890895
);

src/nodes/errors.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,26 @@ class ErrorNodeConnectionManagerNotRunning<T> extends ErrorNodeConnectionManager
101101
exitCode = sysexits.USAGE;
102102
}
103103

104+
class ErrorNodeConnectionManagerStopping<T> extends ErrorNodeConnectionManager<T> {
105+
static description = 'NodeConnectionManager is stopping';
106+
exitCode = sysexits.USAGE;
107+
}
108+
104109
class ErrorNodeConnectionManagerInternalError<T> extends ErrorNodeConnectionManager<T> {
105110
static description = 'There was an internal failure with NodeConnectionManager';
106111
exitCode = sysexits.UNAVAILABLE;
107112
}
108113

114+
class ErrorNodeConnectionManagerNodeIdRequired<T> extends ErrorNodeConnectionManager<T> {
115+
static description = 'No NodeId was provided for establishing a multi connection';
116+
exitCode = sysexits.USAGE;
117+
}
118+
119+
class ErrorNodeConnectionManagerMultiConnectionFailed<T> extends ErrorNodeConnectionManager<T> {
120+
static description = 'Failed to establish any connection during multi connection establishment';
121+
exitCode = sysexits.TEMPFAIL;
122+
}
123+
109124
class ErrorNodePingFailed<T> extends ErrorNodes<T> {
110125
static description =
111126
'Failed to ping the node when attempting to authenticate';
@@ -140,7 +155,10 @@ export {
140155
ErrorNodeConnectionTransportGenericError,
141156
ErrorNodeConnectionManager,
142157
ErrorNodeConnectionManagerNotRunning,
158+
ErrorNodeConnectionManagerStopping,
143159
ErrorNodeConnectionManagerInternalError,
160+
ErrorNodeConnectionManagerNodeIdRequired,
161+
ErrorNodeConnectionManagerMultiConnectionFailed,
144162
ErrorNodePingFailed,
145163
ErrorNodePermissionDenied,
146164
};

0 commit comments

Comments
 (0)