MCPcopy Create free account
hub / github.com/anomalyco/opencode / ToolErrorCard

Function ToolErrorCard

packages/session-ui/src/components/tool-error-card.tsx:21–155  ·  view source on GitHub ↗
(props: ToolErrorCardProps)

Source from the content-addressed store, hash-verified

19}
20
21export function ToolErrorCard(props: ToolErrorCardProps) {
22 const i18n = useI18n()
23 const [state, setState] = createStore({
24 open: props.defaultOpen ?? false,
25 copied: false,
26 })
27 const open = () => props.open ?? state.open
28 const copied = () => state.copied
29 const [split, rest] = splitProps(props, [
30 "tool",
31 "error",
32 "title",
33 "defaultOpen",
34 "open",
35 "onOpenChange",
36 "subtitle",
37 "href",
38 ])
39 const setOpen = (value: boolean) => {
40 if (props.open === undefined) setState("open", value)
41 props.onOpenChange?.(value)
42 }
43 const name = createMemo(() => {
44 if (split.title) return split.title
45 const map: Record<string, string> = {
46 read: "ui.tool.read",
47 list: "ui.tool.list",
48 glob: "ui.tool.glob",
49 grep: "ui.tool.grep",
50 task: "ui.tool.task",
51 webfetch: "ui.tool.webfetch",
52 websearch: "ui.tool.websearch",
53 bash: "ui.tool.shell",
54 apply_patch: "ui.tool.patch",
55 question: "ui.tool.questions",
56 }
57 const key = map[split.tool]
58 if (!key) return split.tool
59 if (!key.includes(".")) return key
60 return i18n.t(key)
61 })
62 const cleaned = createMemo(() => split.error.replace(/^Error:\s*/, "").trim())
63 const tail = createMemo(() => {
64 const value = cleaned()
65 const prefix = `${split.tool} `
66 if (value.startsWith(prefix)) return value.slice(prefix.length)
67 return value
68 })
69
70 const subtitle = createMemo(() => {
71 if (split.subtitle) return split.subtitle
72 const parts = tail().split(": ")
73 if (parts.length <= 1) return i18n.t("ui.toolErrorCard.failed")
74 const head = (parts[0] ?? "").trim()
75 if (!head) return i18n.t("ui.toolErrorCard.failed")
76 return head[0] ? head[0].toUpperCase() + head.slice(1) : i18n.t("ui.toolErrorCard.failed")
77 })
78

Callers

nothing calls this directly

Calls 8

useI18nFunction · 0.90
openFunction · 0.70
copiedFunction · 0.70
copyFunction · 0.70
valueFunction · 0.70
tailFunction · 0.50
nameFunction · 0.50
bodyFunction · 0.50

Tested by

no test coverage detected