From e1ad2a355c84422ef8c6a20f998bc71f2881713a Mon Sep 17 00:00:00 2001
From: Adam <2363879+adamdotdevin@users.noreply.github.com>
Date: Fri, 19 Dec 2025 07:38:33 -0600
Subject: fix(desktop): error handling

---
 packages/desktop/src/pages/error.tsx | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

(limited to 'packages/desktop/src/pages/error.tsx')

diff --git a/packages/desktop/src/pages/error.tsx b/packages/desktop/src/pages/error.tsx
index 66fc81d98..352b9f3e8 100644
--- a/packages/desktop/src/pages/error.tsx
+++ b/packages/desktop/src/pages/error.tsx
@@ -1,5 +1,6 @@
 import { TextField } from "@opencode-ai/ui/text-field"
 import { Logo } from "@opencode-ai/ui/logo"
+import { Button } from "@opencode-ai/ui/button"
 import { Component } from "solid-js"
 import { usePlatform } from "@/context/platform"
 import { Icon } from "@opencode-ai/ui/icon"
@@ -9,9 +10,17 @@ export type InitError = {
   data: Record<string, unknown>
 }
 
-function formatError(error: InitError | undefined): string {
-  if (!error) return "Unknown error"
+function isInitError(error: unknown): error is InitError {
+  return (
+    typeof error === "object" &&
+    error !== null &&
+    "name" in error &&
+    "data" in error &&
+    typeof (error as InitError).data === "object"
+  )
+}
 
+function formatInitError(error: InitError): string {
   const data = error.data
   switch (error.name) {
     case "MCPFailed":
@@ -53,8 +62,16 @@ function formatError(error: InitError | undefined): string {
   }
 }
 
+function formatError(error: unknown): string {
+  if (!error) return "Unknown error"
+  if (isInitError(error)) return formatInitError(error)
+  if (error instanceof Error) return `${error.name}: ${error.message}\n\n${error.stack}`
+  if (typeof error === "string") return error
+  return JSON.stringify(error, null, 2)
+}
+
 interface ErrorPageProps {
-  error: InitError | undefined
+  error: unknown
 }
 
 export const ErrorPage: Component<ErrorPageProps> = (props) => {
@@ -76,6 +93,9 @@ export const ErrorPage: Component<ErrorPageProps> = (props) => {
           label="Error Details"
           hideLabel
         />
+        <Button size="large" onClick={platform.restart}>
+          Restart
+        </Button>
         <div class="flex items-center justify-center gap-1">
           Please report this error to the OpenCode team
           <button
-- 
cgit v1.2.3

