From be106d600cc172eeb5a9e5caefa0f9835c383042 Mon Sep 17 00:00:00 2001 From: vwh Date: Tue, 6 Aug 2024 03:45:50 +0300 Subject: [PATCH] improve errors, fix lint issues --- src/components/landing/dropzone.tsx | 20 ++++++++++++++++---- src/components/ui/input.tsx | 3 +-- src/store/useSQLiteStore.ts | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/landing/dropzone.tsx b/src/components/landing/dropzone.tsx index a3e1cfd..0156466 100644 --- a/src/components/landing/dropzone.tsx +++ b/src/components/landing/dropzone.tsx @@ -32,15 +32,27 @@ export default function UploadFile() { setTables([]); setSelectedTable("0"); - if (acceptedFiles.length > 0) { - await loadDatabase(acceptedFiles[0]); - } - if (fileRejections.length > 0) { const rejectionErrors = fileRejections.flatMap( (rejection) => rejection.errors ); setErrors(rejectionErrors); + return; + } + + if (acceptedFiles.length > 0) { + try { + await loadDatabase(acceptedFiles[0]); + } catch (error) { + console.error("Failed to load database:", error); + if (error instanceof Error) { + return toast(error.message, { position: "bottom-right" }); + } else { + return toast("Failed to load database", { + position: "bottom-right" + }); + } + } } }, [loadDatabase, setTables, setSelectedTable] diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx index 644632d..ee400a5 100644 --- a/src/components/ui/input.tsx +++ b/src/components/ui/input.tsx @@ -2,8 +2,7 @@ import * as React from "react"; import { cn } from "@/lib/utils"; -export interface InputProps - extends React.InputHTMLAttributes {} +type InputProps = React.InputHTMLAttributes; const Input = React.forwardRef( ({ className, type, ...props }, ref) => { diff --git a/src/store/useSQLiteStore.ts b/src/store/useSQLiteStore.ts index 882ab33..92bd48e 100644 --- a/src/store/useSQLiteStore.ts +++ b/src/store/useSQLiteStore.ts @@ -80,6 +80,7 @@ const initializeStore = create((set, get) => ({ } catch (error) { console.error("Failed to load database:", error); set({ isLoading: false, queryError: "Failed to load database" }); + throw error; } },