Skip to content

Commit 4d8ad64

Browse files
adamdotdevinanntnzrb
authored andcommitted
wip(desktop): handle more errors
1 parent 4c78d0d commit 4d8ad64

File tree

5 files changed

+100
-59
lines changed

5 files changed

+100
-59
lines changed

packages/app/src/components/header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ export function Header(props: {
188188
shareURL = await globalSDK.client.session
189189
.share({ sessionID: session.id, directory: currentDirectory() })
190190
.then((r) => r.data?.share?.url)
191+
.catch((e) => {
192+
console.error("Failed to share session", e)
193+
return undefined
194+
})
191195
}
192196
return shareURL
193197
},

packages/app/src/components/prompt-input.tsx

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,11 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
643643
}
644644

645645
const abort = () =>
646-
sdk.client.session.abort({
647-
sessionID: params.id!,
648-
})
646+
sdk.client.session
647+
.abort({
648+
sessionID: params.id!,
649+
})
650+
.catch(() => {})
649651

650652
const addToHistory = (prompt: Prompt, mode: "normal" | "shell") => {
651653
const text = prompt
@@ -883,12 +885,16 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
883885
const agent = local.agent.current()!.name
884886

885887
if (isShellMode) {
886-
sdk.client.session.shell({
887-
sessionID: existing.id,
888-
agent,
889-
model,
890-
command: text,
891-
})
888+
sdk.client.session
889+
.shell({
890+
sessionID: existing.id,
891+
agent,
892+
model,
893+
command: text,
894+
})
895+
.catch((e) => {
896+
console.error("Failed to send shell command", e)
897+
})
892898
return
893899
}
894900

@@ -897,13 +903,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
897903
const commandName = cmdName.slice(1)
898904
const customCommand = sync.data.command.find((c) => c.name === commandName)
899905
if (customCommand) {
900-
sdk.client.session.command({
901-
sessionID: existing.id,
902-
command: commandName,
903-
arguments: args.join(" "),
904-
agent,
905-
model: `${model.providerID}/${model.modelID}`,
906-
})
906+
sdk.client.session
907+
.command({
908+
sessionID: existing.id,
909+
command: commandName,
910+
arguments: args.join(" "),
911+
agent,
912+
model: `${model.providerID}/${model.modelID}`,
913+
})
914+
.catch((e) => {
915+
console.error("Failed to send command", e)
916+
})
907917
return
908918
}
909919
}
@@ -929,13 +939,17 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
929939
model,
930940
})
931941

932-
sdk.client.session.prompt({
933-
sessionID: existing.id,
934-
agent,
935-
model,
936-
messageID,
937-
parts: requestParts,
938-
})
942+
sdk.client.session
943+
.prompt({
944+
sessionID: existing.id,
945+
agent,
946+
model,
947+
messageID,
948+
parts: requestParts,
949+
})
950+
.catch((e) => {
951+
console.error("Failed to send prompt", e)
952+
})
939953
}
940954

941955
return (

packages/app/src/components/terminal.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ export const Terminal = (props: TerminalProps) => {
8282
window.addEventListener("resize", handleResize)
8383
term.onResize(async (size) => {
8484
if (ws && ws.readyState === WebSocket.OPEN) {
85-
await sdk.client.pty.update({
86-
ptyID: local.pty.id,
87-
size: {
88-
cols: size.cols,
89-
rows: size.rows,
90-
},
91-
})
85+
await sdk.client.pty
86+
.update({
87+
ptyID: local.pty.id,
88+
size: {
89+
cols: size.cols,
90+
rows: size.rows,
91+
},
92+
})
93+
.catch(() => {})
9294
}
9395
})
9496
term.onData((data) => {
@@ -106,13 +108,15 @@ export const Terminal = (props: TerminalProps) => {
106108
// })
107109
ws.addEventListener("open", () => {
108110
console.log("WebSocket connected")
109-
sdk.client.pty.update({
110-
ptyID: local.pty.id,
111-
size: {
112-
cols: term.cols,
113-
rows: term.rows,
114-
},
115-
})
111+
sdk.client.pty
112+
.update({
113+
ptyID: local.pty.id,
114+
size: {
115+
cols: term.cols,
116+
rows: term.rows,
117+
},
118+
})
119+
.catch(() => {})
116120
})
117121
ws.addEventListener("message", (event) => {
118122
term.write(event.data)

packages/app/src/context/terminal.tsx

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,49 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
3636
all: createMemo(() => Object.values(store.all)),
3737
active: createMemo(() => store.active),
3838
new() {
39-
sdk.client.pty.create({ title: `Terminal ${store.all.length + 1}` }).then((pty) => {
40-
const id = pty.data?.id
41-
if (!id) return
42-
setStore("all", [
43-
...store.all,
44-
{
45-
id,
46-
title: pty.data?.title ?? "Terminal",
47-
},
48-
])
49-
setStore("active", id)
50-
})
39+
sdk.client.pty
40+
.create({ title: `Terminal ${store.all.length + 1}` })
41+
.then((pty) => {
42+
const id = pty.data?.id
43+
if (!id) return
44+
setStore("all", [
45+
...store.all,
46+
{
47+
id,
48+
title: pty.data?.title ?? "Terminal",
49+
},
50+
])
51+
setStore("active", id)
52+
})
53+
.catch((e) => {
54+
console.error("Failed to create terminal", e)
55+
})
5156
},
5257
update(pty: Partial<LocalPTY> & { id: string }) {
5358
setStore("all", (x) => x.map((x) => (x.id === pty.id ? { ...x, ...pty } : x)))
54-
sdk.client.pty.update({
55-
ptyID: pty.id,
56-
title: pty.title,
57-
size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
58-
})
59+
sdk.client.pty
60+
.update({
61+
ptyID: pty.id,
62+
title: pty.title,
63+
size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
64+
})
65+
.catch((e) => {
66+
console.error("Failed to update terminal", e)
67+
})
5968
},
6069
async clone(id: string) {
6170
const index = store.all.findIndex((x) => x.id === id)
6271
const pty = store.all[index]
6372
if (!pty) return
64-
const clone = await sdk.client.pty.create({
65-
title: pty.title,
66-
})
67-
if (!clone.data) return
73+
const clone = await sdk.client.pty
74+
.create({
75+
title: pty.title,
76+
})
77+
.catch((e) => {
78+
console.error("Failed to clone terminal", e)
79+
return undefined
80+
})
81+
if (!clone?.data) return
6882
setStore("all", index, {
6983
...pty,
7084
...clone.data,
@@ -88,7 +102,9 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
88102
setStore("active", previous?.id)
89103
}
90104
})
91-
await sdk.client.pty.remove({ ptyID: id })
105+
await sdk.client.pty.remove({ ptyID: id }).catch((e) => {
106+
console.error("Failed to close terminal", e)
107+
})
92108
},
93109
move(id: string, to: number) {
94110
const index = store.all.findIndex((f) => f.id === id)

packages/desktop/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default defineConfig({
1010
//
1111
// 1. prevent Vite from obscuring rust errors
1212
clearScreen: false,
13+
build: {
14+
sourcemap: true,
15+
},
1316
// 2. tauri expects a fixed port, fail if that port is not available
1417
server: {
1518
port: 1420,

0 commit comments

Comments
 (0)