Skip to content

Commit

Permalink
Update fragile WebUSB error matching code. (#1122)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
microbit-matt-hillsdon authored May 22, 2023
1 parent cbbe1fa commit 879cfb2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/device/webusb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 879cfb2

Please sign in to comment.