mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-14 10:35:11 +00:00
src/utils: add ensureError() function
Typescript v4.4 no longer assumes that the error in catch is an Error object [1]. This adds a helper function to ensure that caught errors at least match the Error interface. If not, it creates a new Error object with the value as the message. [1]: https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#using-unknown-in-catch-variables
This commit is contained in:
committed by
David Lechner
parent
79db359398
commit
e7d44ea9a9
@@ -53,7 +53,7 @@ import {
|
||||
compile,
|
||||
} from '../mpy/actions';
|
||||
import { RootState } from '../reducers';
|
||||
import { defined, hex, maybe } from '../utils';
|
||||
import { defined, ensureError, hex, maybe } from '../utils';
|
||||
import { fmod, sumComplement32 } from '../utils/math';
|
||||
import { isAndroid } from '../utils/os';
|
||||
import {
|
||||
@@ -487,7 +487,7 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator {
|
||||
|
||||
yield* put(didFinish());
|
||||
} catch (err) {
|
||||
yield* put(didFailToFinish(FailToFinishReasonType.Unknown, err));
|
||||
yield* put(didFailToFinish(FailToFinishReasonType.Unknown, ensureError(err)));
|
||||
yield* disconnectAndCancel();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user