diff --git a/components/workspace/use-cli-commands.tsx b/components/workspace/use-cli-commands.tsx index de51adb..a3f578a 100644 --- a/components/workspace/use-cli-commands.tsx +++ b/components/workspace/use-cli-commands.tsx @@ -22,6 +22,7 @@ import { Link, useSearchParams } from "react-router-dom"; import { FormatBuildErrors } from "./format-build-errors"; import { playgroundService } from "@/data/playground-service"; import { solangBuildService } from "@/data/solang-build-service"; +import { useToast } from "../ui/use-toast"; const PROPOSAL_TIMEOUT = 15 * 60 * 1000; // proposal expires after 15 minutes @@ -30,6 +31,7 @@ export function useCliCommands() { const pathname = usePathname(); const id = useWorkspaceId(); const [, setSearchParams] = useSearchParams(); + const { toast } = useToast(); const wallet = useWallet(); const commands = { @@ -110,9 +112,26 @@ export function useCliCommands() { > ); } catch (err) { - if (err instanceof Error) - terminalContext.setBufferedContent(
Error: {err.message}
); - return; + console.log("err",err) + const errorMessage = err instanceof Error ? err.message : "An unknown error occurred."; + terminalContext.setBufferedContent( ++ Error: {errorMessage}. Please try again or contact + support if this continues. +
+ ); + if (errorMessage.includes("network")) { + toast({ + title: "Network Error", + description: "Please check your internet connection and try again.", + }); + } else { + toast({ + title: "Audit Failed", + description: + errorMessage || "Something went wrong. Please try again.", + }); + } } }, build: async () => { @@ -160,10 +179,18 @@ export function useCliCommands() { > ); return; + } else { + throw new Error("Build failed: DLL generation returned undefined."); } } catch (err) { - if (err instanceof Error) - terminalContext.setBufferedContent(Error: {errorMessage}
+ > + ); + + toast({ + title: "Test Failed", + description: errorMessage, + }); return; } }, deploy: async () => { + try { if (typeof id !== "string") { terminalContext.setBufferedContent( <> @@ -217,7 +255,8 @@ export function useCliCommands() { if (!dll) { terminalContext.setBufferedContent( <> -Contract not built.
+ Warning: + No contract found to deploy. Please ensure the contract is built successfully before attempting deployment. > ); return; @@ -243,6 +282,18 @@ export function useCliCommands() {Error: {errorMessage}
+ > + ); + toast({ + title: "Deployment Failed", + description: errorMessage, + }); + } }, check: async (id: string) => { if (!id) return `Please enter the Transaction ID.`; @@ -280,41 +331,76 @@ export function useCliCommands() { saveAs(file); }, share: async () => { - if (typeof id !== "string") throw new Error("id is not string"); - const start = `${pathname}/`; - terminalContext.setBufferedContent( - <> -Loading files...
- > - ); - const files = ( - await db.files.filter((file) => file.path.startsWith(start)).toArray() - ).map((file) => ({ - path: decodeURIComponent(file.path.replace(start, "")), - contents: file.contents, - })); + try { + // Validate `id` input + if (typeof id !== "string") { + terminalContext.setBufferedContent( + <> ++ Error: Invalid workspace identifier. Please provide a valid + workspace ID. +
+ > + ); + return; + } - terminalContext.setBufferedContent( - <> -Loaded files: {files.map((i) => i.path).join(", ")}
-
-
Loading files...
+ > + ); + const files = ( + await db.files.filter((file) => file.path.startsWith(start)).toArray() + ).map((file) => ({ + path: decodeURIComponent(file.path.replace(start, "")), + contents: file.contents, + })); - try { - const { id } = await playgroundService.createShare(files); + terminalContext.setBufferedContent( + <> +Loaded files: {files.map((i) => i.path).join(", ")}
+
+
Share link generated successfully!
+{err.message?.trim() || "There was an error generating the share link. Please try again later."}
); - return; + const errorMessage = + err instanceof Error && err.message + ? err.message.trim() + : "An unexpected error occurred while generating the share link. Please try again."; + + // Log error for debugging + console.error("Share Error:", err); + + // Notify user of error + terminalContext.setBufferedContent( + <> +Error: {errorMessage}
+ > + ); + + // Optional error toast + toast({ + title: "Share Link Error", + description: errorMessage, + }); } }, };