Skip to content

Commit

Permalink
Avoid uncaught rejections when usbmux is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 6, 2024
1 parent 3042807 commit ec1e743
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const readMessageFromLockdowndStream = async (stream: net.Socket): Promise<Lockd

const payloadLength = header.readUInt32BE(0);
const payload = await readBytes(stream, payloadLength);

const data = plist.parse(payload.toString('utf8'));
if ((data as any).Error) {
throw new Error(`Received lockdown error: ${(data as any).Error.toString()}`);
Expand Down Expand Up @@ -169,6 +169,11 @@ export class UsbmuxClient {
const connectionDeferred = getDeferred<net.Socket>();
this.deviceMonitorConnection = connectionDeferred.promise;

// Ignore any uncaught errors here - they'll be thrown by any pending getDevices()
// calls waiting on the promise, or thrown separately (in the catch block below) by
// this call, but we don't want uncaught rejection issues in other cases.
connectionDeferred.promise.catch(() => {});

try {
const conn = await connectSocket(this.connectionOptions);

Expand Down

0 comments on commit ec1e743

Please sign in to comment.