mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
fix: image reading error, also add error toast for event bus
This commit is contained in:
@@ -367,6 +367,27 @@ function App() {
|
||||
}
|
||||
})
|
||||
|
||||
event.on(SessionApi.Event.Error.type, (evt) => {
|
||||
const error = evt.properties.error
|
||||
const message = (() => {
|
||||
if (!error) return "An error occured"
|
||||
|
||||
if (typeof error === "object") {
|
||||
const data = error.data
|
||||
if ("message" in data && typeof data.message === "string") {
|
||||
return data.message
|
||||
}
|
||||
}
|
||||
return String(error)
|
||||
})()
|
||||
|
||||
toast.show({
|
||||
variant: "error",
|
||||
message,
|
||||
duration: 5000,
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<box
|
||||
width={dimensions().width}
|
||||
|
||||
@@ -51,6 +51,7 @@ import { $, fileURLToPath } from "bun"
|
||||
import { ConfigMarkdown } from "../config/markdown"
|
||||
import { SessionSummary } from "./summary"
|
||||
import { Config } from "@/config/config"
|
||||
import { NamedError } from "@/util/error"
|
||||
|
||||
export namespace SessionPrompt {
|
||||
const log = Log.create({ service: "session.prompt" })
|
||||
@@ -735,17 +736,8 @@ export namespace SessionPrompt {
|
||||
}
|
||||
}
|
||||
const args = { filePath: filepath, offset, limit }
|
||||
const result = await ReadTool.init().then((t) =>
|
||||
t.execute(args, {
|
||||
sessionID: input.sessionID,
|
||||
abort: new AbortController().signal,
|
||||
agent: input.agent!,
|
||||
messageID: info.id,
|
||||
extra: { bypassCwdCheck: true },
|
||||
metadata: async () => {},
|
||||
}),
|
||||
)
|
||||
return [
|
||||
|
||||
const pieces: MessageV2.Part[] = [
|
||||
{
|
||||
id: Identifier.ascending("part"),
|
||||
messageID: info.id,
|
||||
@@ -754,6 +746,19 @@ export namespace SessionPrompt {
|
||||
synthetic: true,
|
||||
text: `Called the Read tool with the following input: ${JSON.stringify(args)}`,
|
||||
},
|
||||
]
|
||||
|
||||
await ReadTool.init()
|
||||
.then(async (t) => {
|
||||
const result = await t.execute(args, {
|
||||
sessionID: input.sessionID,
|
||||
abort: new AbortController().signal,
|
||||
agent: input.agent!,
|
||||
messageID: info.id,
|
||||
extra: { bypassCwdCheck: true },
|
||||
metadata: async () => {},
|
||||
})
|
||||
pieces.push(
|
||||
{
|
||||
id: Identifier.ascending("part"),
|
||||
messageID: info.id,
|
||||
@@ -768,7 +773,28 @@ export namespace SessionPrompt {
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
},
|
||||
]
|
||||
)
|
||||
})
|
||||
.catch((error) => {
|
||||
log.error("failed to read file", { error })
|
||||
const message = error instanceof Error ? error.message : error.toString()
|
||||
Bus.publish(Session.Event.Error, {
|
||||
sessionID: input.sessionID,
|
||||
error: new NamedError.Unknown({
|
||||
message,
|
||||
}).toObject(),
|
||||
})
|
||||
pieces.push({
|
||||
id: Identifier.ascending("part"),
|
||||
messageID: info.id,
|
||||
sessionID: input.sessionID,
|
||||
type: "text",
|
||||
synthetic: true,
|
||||
text: `Read tool failed to read ${filepath} with the following error: ${message}`,
|
||||
})
|
||||
})
|
||||
|
||||
return pieces
|
||||
}
|
||||
|
||||
if (part.mime === "application/x-directory") {
|
||||
|
||||
Reference in New Issue
Block a user