mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-07-28 04:08:05 +00:00
usb/sagas: show unexpected error alerts
Add more error alerts when failing to connect to a Pybricks hub over USB. We will need user feedback on what triggered the error to be able to write a helpful error message, so we are using the unexpected error alert for now.
This commit is contained in:
+24
-6
@@ -128,7 +128,9 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: show unexpected error message to user here
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', { error: reqDeviceErr }),
|
||||
);
|
||||
console.error('Failed to request USB device:', reqDeviceErr);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
@@ -186,7 +188,7 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
|
||||
const [, selectErr] = yield* call(() => maybe(usbDevice.selectConfiguration(1)));
|
||||
if (selectErr) {
|
||||
// TODO: show error message to user here
|
||||
yield* put(alertsShowAlert('alerts', 'unexpectedError', { error: selectErr }));
|
||||
console.error('Failed to select USB device configuration:', selectErr);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
@@ -257,7 +259,11 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
),
|
||||
);
|
||||
if (fwVerError || fwVerResult?.status !== 'ok') {
|
||||
// TODO: show error message to user here
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', {
|
||||
error: fwVerError || ensureError(fwVerResult?.status),
|
||||
}),
|
||||
);
|
||||
console.error('Failed to get firmware version:', fwVerError);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
@@ -313,7 +319,11 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
),
|
||||
);
|
||||
if (nameError || nameResult?.status !== 'ok') {
|
||||
// TODO: show error message to user here
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', {
|
||||
error: nameError || ensureError(nameResult?.status),
|
||||
}),
|
||||
);
|
||||
console.error('Failed to get device name:', nameError);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
@@ -340,7 +350,11 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
),
|
||||
);
|
||||
if (swVerError || swVerResult?.status !== 'ok') {
|
||||
// TODO: show error message to user here
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', {
|
||||
error: swVerError || ensureError(swVerResult?.status),
|
||||
}),
|
||||
);
|
||||
console.error('Failed to get software version:', swVerError);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
@@ -382,7 +396,11 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
|
||||
),
|
||||
);
|
||||
if (hubCapErr || hubCapResult?.status !== 'ok') {
|
||||
// TODO: show error message to user here
|
||||
yield* put(
|
||||
alertsShowAlert('alerts', 'unexpectedError', {
|
||||
error: hubCapErr || ensureError(hubCapResult?.status),
|
||||
}),
|
||||
);
|
||||
console.error('Failed to get hub capabilities:', hubCapErr);
|
||||
yield* put(usbDidFailToConnectPybricks());
|
||||
yield* cleanup();
|
||||
|
||||
Reference in New Issue
Block a user