From fb55bd5056a5db9ac3dd1d9cbf171ade0d0db2e8 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Mon, 22 May 2023 09:26:19 +0100 Subject: [PATCH] Update fragile WebUSB error matching code. The text now appears to be prefixed, we have e.g. > DOMException: Failed to execute 'requestDevice' on 'USB': No device selected. Probably still worth it unfortunately. --- src/device/webusb.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/device/webusb.ts b/src/device/webusb.ts index 41f3f2b8f..53a858c11 100644 --- a/src/device/webusb.ts +++ b/src/device/webusb.ts @@ -427,18 +427,20 @@ const enrichedError = (err: any): WebUSBError => { if (!err.message && err.promise && err.reason) { err = err.reason; } - // This comes from DAPjs's WebUSB open. - if (err.message === "No valid interfaces found.") { + // This is somewhat fragile but worth it for scenario specific errors. + // These messages changed to be prefixed in 2023 so we've relaxed the checks. + if (/No valid interfaces found/.test(err.message)) { + // This comes from DAPjs's WebUSB open. return new WebUSBError({ code: "update-req", message: err.message, }); - } else if (err.message === "No device selected.") { + } else if (/No device selected/.test(err.message)) { return new WebUSBError({ code: "no-device-selected", message: err.message, }); - } else if (err.message === "Unable to claim interface.") { + } else if (/Unable to claim interface/.test(err.message)) { return new WebUSBError({ code: "clear-connect", message: err.message,