From b79f5165bd6ec74263dc6290933f3495f0a1e6da Mon Sep 17 00:00:00 2001
From: Neil <4138956+nwparker@users.noreply.github.com>
Date: Tue, 10 Nov 2026 08:09:36 -0800
Subject: [PATCH] feat(vm-build): show the last 20 lines of a recipe error
under an earlier-lines note (#281)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The cause usually prints last, so the Details window now keeps the tail,
opens scrolled to the end, and notes '…N earlier lines' (plurals) at the
top. Copy details still copies the full text.
---
.../VmBuildErrorDetails.test.tsx | 16 ++++--
.../worktree-creation/VmBuildErrorDetails.tsx | 54 ++++++++++---------
.../VmBuildSheetRecipeFailures.fixture.tsx | 2 +-
.../src/i18n/en-runtime-required.json | 5 +-
src/renderer/src/i18n/locales/en.json | 5 +-
5 files changed, 44 insertions(+), 38 deletions(-)
diff --git a/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.test.tsx b/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.test.tsx
index 65c8d6f1d1e..33ae558308d 100644
--- a/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.test.tsx
+++ b/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.test.tsx
@@ -74,17 +74,23 @@ it('shows a plain summary and keeps the raw recipe error collapsed behind Detail
expect(toggle.getAttribute('aria-expanded')).toBe('true')
const text = screen.getByTestId('vm-build-error-details-text').textContent
expect(text).toBe('Recipe exited with code 1.\n\nError: snapshot snap_7f2c not found')
- expect(screen.queryByText(/Showing the first/)).toBeNull()
+ expect(screen.queryByText(/earlier line/)).toBeNull()
})
-it('truncates long errors to 20 lines but copies all of them, then confirms', async () => {
+it('notes a single hidden earlier line in the singular', () => {
+ const error = Array.from({ length: 21 }, (_, index) => `line ${index + 1}`).join('\n')
+ render()
+ fireEvent.click(screen.getByRole('button', { name: 'Details' }))
+ expect(screen.getByText('…1 earlier line. Copy details includes it.')).toBeTruthy()
+})
+
+it('shows the last 20 lines of a long error but copies all of them, then confirms', async () => {
const error = Array.from({ length: 30 }, (_, index) => `line ${index + 1}`).join('\n')
render()
fireEvent.click(screen.getByRole('button', { name: 'Details' }))
const text = screen.getByTestId('vm-build-error-details-text').textContent ?? ''
- expect(text.split('\n')).toHaveLength(20)
- expect(text).not.toContain('line 21')
- expect(screen.getByText(/Showing the first 20 of 30 lines/)).toBeTruthy()
+ expect(text.split('\n')).toEqual(Array.from({ length: 20 }, (_, index) => `line ${index + 11}`))
+ expect(screen.getByText('…10 earlier lines. Copy details includes them.')).toBeTruthy()
await act(async () => {
fireEvent.click(screen.getByRole('button', { name: 'Copy details' }))
diff --git a/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.tsx b/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.tsx
index 06c40c1b521..ee90d06115e 100644
--- a/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.tsx
+++ b/src/renderer/src/components/worktree-creation/VmBuildErrorDetails.tsx
@@ -6,20 +6,16 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/component
import { useTranslate } from '@/i18n/use-translate'
import { cn } from '@/lib/utils'
-/** Raw error lines shown before the rest is left to Copy. */
+/** Raw error lines shown; earlier ones are left to Copy. */
export const ERROR_DETAILS_VISIBLE_LINES = 20
-export function truncateErrorDetails(text: string): {
- visible: string
- totalLines: number
- truncated: boolean
-} {
+/** Keeps the last lines, since recipes and their tools usually print the cause at the end. */
+export function truncateErrorDetails(text: string): { visible: string; hiddenLines: number } {
const lines = text.split('\n')
- const truncated = lines.length > ERROR_DETAILS_VISIBLE_LINES
+ const hiddenLines = Math.max(0, lines.length - ERROR_DETAILS_VISIBLE_LINES)
return {
- visible: truncated ? lines.slice(0, ERROR_DETAILS_VISIBLE_LINES).join('\n') : text,
- totalLines: lines.length,
- truncated
+ visible: hiddenLines > 0 ? lines.slice(hiddenLines).join('\n') : text,
+ hiddenLines
}
}
@@ -31,7 +27,13 @@ export function VmBuildErrorDetails({ text }: { text: string }): React.JSX.Eleme
const t = useTranslate()
const [open, setOpen] = React.useState(false)
const [copied, setCopied] = React.useState(false)
- const { visible, totalLines, truncated } = React.useMemo(() => truncateErrorDetails(text), [text])
+ const { visible, hiddenLines } = React.useMemo(() => truncateErrorDetails(text), [text])
+
+ const scrollToEnd = React.useCallback((node: HTMLPreElement | null): void => {
+ if (node) {
+ node.scrollTop = node.scrollHeight
+ }
+ }, [])
React.useEffect(() => {
if (!copied) {
@@ -77,29 +79,29 @@ export function VmBuildErrorDetails({ text }: { text: string }): React.JSX.Eleme
+ {hiddenLines > 0 ? (
+
+ {t(
+ 'auto.components.worktree.creation.VmBuildErrorDetails.earlierLines',
+ '…{{count}} earlier lines. Copy details includes them.',
+ {
+ count: hiddenLines,
+ defaultValue_one: '…{{count}} earlier line. Copy details includes it.'
+ }
+ )}
+
+ ) : null}
{/* Capped and scrollable too, so one very long wrapped line can't bury the actions. */}
{visible}
-
- {truncated ? (
-
- {t(
- 'auto.components.worktree.creation.VmBuildErrorDetails.truncated',
- 'Showing the first {{shown}} of {{count}} lines. Copy includes all of them.',
- {
- shown: ERROR_DETAILS_VISIBLE_LINES,
- count: totalLines,
- defaultValue_one:
- 'Showing the first {{shown}} of {{count}} line. Copy includes all of it.'
- }
- )}
-
- ) : null}
+