From c1cde5b94f7eba4b9dfefa25dda30b1b298e8983 Mon Sep 17 00:00:00 2001 From: nthouliss Date: Fri, 1 Apr 2022 14:56:55 +1100 Subject: [PATCH] Add error guards to catch blocks --- src/components/dice/DiceInteraction.tsx | 4 +++- src/helpers/grid.ts | 4 +++- src/hooks/useImageDrop.ts | 10 ++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/dice/DiceInteraction.tsx b/src/components/dice/DiceInteraction.tsx index 88cf213..8494c24 100644 --- a/src/components/dice/DiceInteraction.tsx +++ b/src/components/dice/DiceInteraction.tsx @@ -108,7 +108,9 @@ function DiceInteraction({ } }); } catch (error) { - setError(error); + if (error instanceof Error) { + setError(error); + } } }, [onSceneMount]); diff --git a/src/helpers/grid.ts b/src/helpers/grid.ts index 2c5db2d..7e7a8e6 100644 --- a/src/helpers/grid.ts +++ b/src/helpers/grid.ts @@ -562,7 +562,9 @@ export async function getGridSizeFromImage(image: HTMLImageElement) { try { prediction = await gridSizeML(image, candidates); } catch (error) { - logError(error); + if (error instanceof Error) { + logError(error); + } } if (!prediction) { diff --git a/src/hooks/useImageDrop.ts b/src/hooks/useImageDrop.ts index dde5616..749cdcc 100644 --- a/src/hooks/useImageDrop.ts +++ b/src/hooks/useImageDrop.ts @@ -67,10 +67,12 @@ function useImageDrop( } } } catch (e) { - if (e.message === "Failed to fetch") { - addToast("Unable to import image: failed to fetch"); - } else { - addToast("Unable to import image"); + if (e instanceof Error) { + if (e.message === "Failed to fetch") { + addToast("Unable to import image: failed to fetch"); + } else { + addToast("Unable to import image"); + } } } }