Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(md-view): tell a render failure from a capture failure

review41966f775f91
diff --git a/src/renderer/nodes/TerminalMarkdownView.test.tsx b/src/renderer/nodes/TerminalMarkdownView.test.tsx
index 2021dc0b3..b04142fe6 100644
--- a/src/renderer/nodes/TerminalMarkdownView.test.tsx
+++ b/src/renderer/nodes/TerminalMarkdownView.test.tsx
@@ -157,12 +157,12 @@ describe('TerminalMarkdownView', () => {
expect(md.render).not.toHaveBeenCalled()
})
- it('a renderer that throws lands in the error state, and ↻ works again', async () => {
+ it('a renderer that throws says RENDER failed (not capture), and ↻ works again', async () => {
md.throwRender = true
mount()
pending[0].resolve('boom')
await settle()
- expect(content().textContent).toBe('Could not capture this terminal’s output.')
+ expect(content().textContent).toBe('Could not render this terminal’s output.')
expect(refresh().disabled).toBe(false)
md.throwRender = false
act(() => refresh().click())
diff --git a/src/renderer/nodes/TerminalMarkdownView.tsx b/src/renderer/nodes/TerminalMarkdownView.tsx
index 1e4d40b5e..9006133e2 100644
--- a/src/renderer/nodes/TerminalMarkdownView.tsx
+++ b/src/renderer/nodes/TerminalMarkdownView.tsx
@@ -34,7 +34,10 @@ export interface TerminalMarkdownViewProps {
type ViewState =
| { kind: 'loading' }
| { kind: 'empty' }
- | { kind: 'error' }
+ /** `capture` = the capture (or the renderer chunk) never arrived; `render` = the text arrived and
+ * the renderer threw on it. Different facts, different sentences: telling a user their terminal
+ * could not be captured when it was captured fine sends them after the wrong problem. */
+ | { kind: 'error'; stage: 'capture' | 'render' }
| { kind: 'ready'; html: string; kept: number; dropped: number }
export function TerminalMarkdownView({ nodeId, capture, hint }: TerminalMarkdownViewProps) {
@@ -51,15 +54,16 @@ export function TerminalMarkdownView({ nodeId, capture, hint }: TerminalMarkdown
const run = useCallback(() => {
const token = ++reqRef.current
setCapturing(true)
- // `.then(ok).catch(fail)`, not `.then(ok, fail)`: a throw INSIDE the fulfilment handler (the
- // renderer on some pathological capture) must land in the error state too — with the two-arg
- // form it escaped as an unhandled rejection and left `capturing` true, ↻ disabled for good.
+ // `.then(ok).catch(fail)`, not `.then(ok, fail)`: nothing thrown in the fulfilment path may
+ // escape as an unhandled rejection and leave `capturing` true, ↻ disabled for good. A renderer
+ // throw is caught inside (→ 'render'); the catch is the capture/import leg (→ 'capture').
void Promise.all([captureRef.current(nodeId), import('../lib/terminalOutputMarkdown')])
.then(([text, md]) => {
if (token !== reqRef.current) return
- const tail = md.tailOutputLines(text)
- setView(
- tail.text
+ let next: ViewState
+ try {
+ const tail = md.tailOutputLines(text)
+ next = tail.text
? {
kind: 'ready',
html: md.renderTerminalOutput(tail.text),
@@ -69,12 +73,15 @@ export function TerminalMarkdownView({ nodeId, capture, hint }: TerminalMarkdown
dropped: tail.dropped
}
: { kind: 'empty' }
- )
+ } catch {
+ next = { kind: 'error', stage: 'render' }
+ }
+ setView(next)
setCapturing(false)
})
.catch(() => {
if (token !== reqRef.current) return
- setView({ kind: 'error' })
+ setView({ kind: 'error', stage: 'capture' })
setCapturing(false)
})
}, [nodeId])
@@ -132,7 +139,9 @@ export function TerminalMarkdownView({ nodeId, capture, hint }: TerminalMarkdown
? 'Capturing…'
: view.kind === 'empty'
? 'Nothing captured from this terminal.'
- : 'Could not capture this terminal’s output.'}
+ : view.stage === 'render'
+ ? 'Could not render this terminal’s output.'
+ : 'Could not capture this terminal’s output.'}
</div>
)}
</div>