diff --git a/src/firmware/actions.ts b/src/firmware/actions.ts index 8a4bc484..5dff5c99 100644 --- a/src/firmware/actions.ts +++ b/src/firmware/actions.ts @@ -4,6 +4,7 @@ import { FirmwareReaderError, HubType } from '@pybricks/firmware'; import { createAction } from '../actions'; import { Hub } from '../components/hubPicker'; +import { isError } from '../utils'; export enum MetadataProblem { Missing = 'metadata.missing', @@ -144,16 +145,6 @@ export const didFinish = createAction(() => ({ type: 'flashFirmware.action.didFinish', })); -function isError(err: unknown): err is Error { - const maybeError = err as Error; - - return ( - maybeError !== undefined && - typeof maybeError.name === 'string' && - typeof maybeError.message === 'string' - ); -} - // FIXME: get rid of this monstrosity const didFailToFinishType = 'flashFirmware.action.didFailToFinish'; diff --git a/src/utils/index.ts b/src/utils/index.ts index 1b154e1a..309a34cf 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020-2022 The Pybricks Authors +// Copyright (c) 2020-2026 The Pybricks Authors /** * Asserts that an assumption is true. This is used to detect programmer errors @@ -43,7 +43,7 @@ export function hex(n: number, pad: number): string { return `0x${n.toString(16).padStart(pad, '0')}`; } -function isError(err: unknown): err is Error { +export function isError(err: unknown): err is Error { const maybeError = err as Error; return (