Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 9b934bf7 authored by Danny Lin's avatar Danny Lin
Browse files

fastboot: Fix silent error suppression in connect()

Clean up the error handling in _validateAndConnectDevice() to fix
silently ignored exceptions.
parent 900539f5
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -115,15 +115,13 @@ export class FastbootDevice {
            await this.device.claimInterface(0); // fastboot
        } catch (error) {
            // Propagate exception from waitForConnect()
            let rejected = false;
            if (this._connectReject !== null) {
                this._connectReject(error);
                this._connectResolve = null;
                this._connectReject = null;
                rejected = true;
            }

            if (rethrowErrors && rejected) {
            if (rethrowErrors) {
                throw error;
            }
        }
@@ -223,7 +221,18 @@ export class FastbootDevice {
            navigator.usb.addEventListener("connect", async (event) => {
                common.logDebug("USB device connected");
                this.device = event.device;

                // Check whether waitForConnect() is pending and save it for later
                let hasPromiseReject = this._connectReject !== null;
                try {
                    await this._validateAndConnectDevice(false);
                } catch (error) {
                    // Only rethrow errors from the event handler if waitForConnect()
                    // didn't already handle them
                    if (!hasPromiseReject) {
                        throw error;
                    }
                }
            });

            this._registeredUsbListeners = true;