File tree 1 file changed +10
-2
lines changed
packages/hardware-ledger/src
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -377,12 +377,20 @@ export class LedgerKeyAgent extends KeyAgentBase {
377
377
}
378
378
379
379
private static attachDisconnectionCleanupHandler ( transport : LedgerTransportType ) {
380
- const onDisconnect = ( ) => {
380
+ const onDisconnect = async ( ) => {
381
381
transport . off ( 'disconnect' , onDisconnect ) ;
382
382
this . deviceConnections = this . deviceConnections . filter (
383
383
( { deviceConnection } ) => deviceConnection . transport !== transport
384
384
) ;
385
- void transport . close ( ) ;
385
+
386
+ try {
387
+ await transport . close ( ) ;
388
+ } catch ( error ) {
389
+ // hw-transport-webusb also adds a disconnect event listener while creating a Ledger transport,
390
+ // so calling close() method will throw an error, since the device is already disconnected
391
+ if ( error instanceof Error && error . message . includes ( 'The device was disconnected.' ) ) return ;
392
+ throw new errors . TransportError ( 'Failed to close transport after device disconnection' , error ) ;
393
+ }
386
394
} ;
387
395
transport . on ( 'disconnect' , onDisconnect ) ;
388
396
}
You can’t perform that action at this time.
0 commit comments