mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
feat(vm-build): show the last 20 lines of a recipe error under an earlier-lines note (#281)
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.
This commit is contained in:
@@ -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(<Card failure={{ kind: 'create', error }} />)
|
||||
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(<Card failure={{ kind: 'create', error }} />)
|
||||
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' }))
|
||||
|
||||
@@ -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
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent animation="height">
|
||||
<div className="flex flex-col gap-1.5 pt-1.5">
|
||||
{hiddenLines > 0 ? (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{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.'
|
||||
}
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
{/* Capped and scrollable too, so one very long wrapped line can't bury the actions. */}
|
||||
<pre
|
||||
// Starts scrolled to the end, where the cause usually is, like the visible window.
|
||||
ref={scrollToEnd}
|
||||
data-testid="vm-build-error-details-text"
|
||||
tabIndex={0}
|
||||
className="scrollbar-sleek max-h-80 max-w-full overflow-auto whitespace-pre-wrap break-words rounded-md bg-muted/40 px-3 py-2 font-mono text-xs leading-5 text-muted-foreground outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus-ring"
|
||||
>
|
||||
{visible}
|
||||
</pre>
|
||||
<div className="flex flex-wrap items-center justify-end gap-x-3 gap-y-1">
|
||||
{truncated ? (
|
||||
<span className="mr-auto text-xs text-muted-foreground">
|
||||
{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.'
|
||||
}
|
||||
)}
|
||||
</span>
|
||||
) : null}
|
||||
<div className="flex items-center justify-end">
|
||||
<Button type="button" variant="ghost" size="xs" onClick={copy}>
|
||||
{copied ? <Check aria-hidden /> : <Copy aria-hidden />}
|
||||
{copied
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ const LONG_ERROR = [
|
||||
'Recipe aborted after 3 of 5 steps.'
|
||||
].join('\n')
|
||||
|
||||
/** Truncated: more than 20 lines, so the note says Copy takes the rest. */
|
||||
/** Truncated: more than 20 lines, so only the last 20 show, under a note on the earlier ones. */
|
||||
export const recipeDetailsTruncated = expanded(
|
||||
frame(entry({ status: 'error', provisioningLog: LOG, errorAt: T0 + 98_000 }), LONG_ERROR)
|
||||
)
|
||||
|
||||
+2
-3
@@ -1340,9 +1340,8 @@
|
||||
"worktree": {
|
||||
"creation": {
|
||||
"VmBuildErrorDetails": {
|
||||
"truncated": "Showing the first {{shown}} of {{count}} lines. Copy includes all of them.",
|
||||
"truncated_one": "Showing the first {{shown}} of {{count}} line. Copy includes all of it.",
|
||||
"truncated_other": "Showing the first {{shown}} of {{count}} lines. Copy includes all of them."
|
||||
"earlierLines_one": "…{{count}} earlier line. Copy details includes it.",
|
||||
"earlierLines_other": "…{{count}} earlier lines. Copy details includes them."
|
||||
},
|
||||
"VmBuildFailureCard": {
|
||||
"checksBodyCloud2_one": "Open it anyway and fix it inside the workspace, or run the checks again after changing your project.",
|
||||
|
||||
@@ -4356,12 +4356,11 @@
|
||||
"VmBuildErrorDetails": {
|
||||
"copyFailed": "Couldn’t copy the details.",
|
||||
"toggle": "Details",
|
||||
"truncated": "Showing the first {{shown}} of {{count}} lines. Copy includes all of them.",
|
||||
"copied": "Copied",
|
||||
"copy": "Copy details",
|
||||
"copiedStatus": "Details copied",
|
||||
"truncated_one": "Showing the first {{shown}} of {{count}} line. Copy includes all of it.",
|
||||
"truncated_other": "Showing the first {{shown}} of {{count}} lines. Copy includes all of them."
|
||||
"earlierLines_one": "…{{count}} earlier line. Copy details includes it.",
|
||||
"earlierLines_other": "…{{count}} earlier lines. Copy details includes them."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user