firmware/installPybricksDialog/hooks: dispatch error if no url

Dispatch an error in case there is no firmware URL. Normally this should
never happen, but currently it does because we don't have EV3 firmware
yet. The error is more useful than just spinning forever.
This commit is contained in:
Attila Farago
2025-08-30 19:12:53 -04:00
committed by David Lechner
parent c6302232e3
commit fadc3bc8c7
+4 -2
View File
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022-2023 The Pybricks Authors
// Copyright (c) 2022-2025 The Pybricks Authors
// based on https://usehooks-ts.com/react-hook/use-fetch
import { FirmwareMetadata, FirmwareReader } from '@pybricks/firmware';
@@ -78,8 +78,10 @@ export function useFirmware(hubType: Hub): State {
const [state, dispatch] = useReducer(fetchReducer, initialState);
useEffect(() => {
// Do nothing if the url is not given
// Raise error if the url is not given, to show that something is wrong
// instead of a misleading intermediate state.
if (!url) {
dispatch({ type: 'error', payload: new Error('No URL for this hub type') });
return;
}