Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fragile WebUSB error matching code. #1122

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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