Skip to content

Commit 0e16a6e

Browse files
feat(rpc): expose missing response groups on timeout (#604)
1 parent cb91e7b commit 0e16a6e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/programs/rpc/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import type {
1313
} from "./io.js";
1414

1515
export class MissingResponsesError extends Error {
16-
constructor(message: string) {
16+
missingGroups: string[][];
17+
constructor(message: string, missingGroups: string[][] = []) {
1718
super(message);
19+
this.missingGroups = missingGroups;
1820
}
1921
}
2022
export type RPCRequestAllOptions<_Q, R> = RPCRequestResponseOptions<R> &
@@ -84,6 +86,7 @@ export const queryAll = async <Q, R>(
8486
throw new MissingResponsesError(
8587
"Did not receive responses from all shards: " +
8688
JSON.stringify(missingReponses),
89+
missingReponses,
8790
);
8891
}
8992
};

packages/programs/rpc/test/index.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { TestSession } from "@peerbit/test-utils";
1111
import { AbortError, delay, waitFor, waitForResolved } from "@peerbit/time";
1212
import { expect } from "chai";
1313
import {
14+
MissingResponsesError,
1415
RPC,
1516
type RPCResponse,
1617
type RequestEvent,
@@ -734,4 +735,24 @@ describe("queryAll", () => {
734735
await expect(promise).rejectedWith("TestAborted");
735736
expect(+new Date() - t1).lessThan(1000);
736737
});
738+
739+
it("reports missing groups on timeout", async () => {
740+
clients[1].delay = 200;
741+
const missingGroup = [[clients[1].node.identity.publicKey.hashcode()]];
742+
try {
743+
await queryAll(
744+
clients[0].query,
745+
missingGroup,
746+
new Body({ arr: new Uint8Array([1]) }),
747+
() => {},
748+
{ timeout: 50 },
749+
);
750+
expect.fail("Expected MissingResponsesError");
751+
} catch (error) {
752+
expect(error).to.be.instanceOf(MissingResponsesError);
753+
expect((error as MissingResponsesError).missingGroups).to.deep.equal(
754+
missingGroup,
755+
);
756+
}
757+
});
737758
});

0 commit comments

Comments
 (0)