File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,10 @@ import type {
1313} from "./io.js" ;
1414
1515export 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}
2022export 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} ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { TestSession } from "@peerbit/test-utils";
1111import { AbortError , delay , waitFor , waitForResolved } from "@peerbit/time" ;
1212import { expect } from "chai" ;
1313import {
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} ) ;
You can’t perform that action at this time.
0 commit comments