fix(cli): print capture setup commands on their own lines (#8374)

* fix(cli): print capture setup commands on their own lines

When a capture fails because no browser can be set up on Linux ARM64, the
reason stays on the `Capture failed:` line and the setup commands this CLI
writes follow it on separate lines, instead of being joined to it with
`\x0a`. The design style extraction notice now keeps its reason on one line
like the other capture warnings. JSON output and BLOCKED.md are unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* refactor(cli): name the setup lines field for what it holds

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-21 14:20:57 +00:00
committed by GitHub
co-authored by Claude Fable 5.2
parent fbbf5ee67e
commit 281f1a2a48
7 changed files with 86 additions and 19 deletions
+5 -1
View File
@@ -430,7 +430,11 @@ you build.
Each warning, and the reason on a `Capture failed:` line, is printed on one
line: a line break inside the text is shown as `\x0a` instead of starting a new
terminal line. `--json` output is unchanged and carries the full text.
terminal line. `--json` output is unchanged and carries the full text. The
`Design style extraction failed` line printed during a capture follows the same
rule. When a capture fails because no browser can be set up on Linux ARM64, the
reason stays on the `Capture failed:` line and the setup commands follow it on
lines of their own, ready to copy.
Downloaded fonts are saved under `assets/fonts/`, and their CSS references point
to those local files. Distinct URLs such as `demo.woff2?v=1` and
+4 -4
View File
@@ -24,7 +24,7 @@ import {
} from "@hyperframes/engine/chrome-host-ceiling";
import { getFreeDiskMb } from "../telemetry/system.js";
import { BrowserDownloadStalledError, installInChild } from "./installInChild.js";
import { normalizeErrorMessage } from "../utils/errorMessage.js";
import { normalizeErrorMessage, SetupStepsError } from "../utils/errorMessage.js";
import { runRenderSetupWorker } from "../utils/cancellableProcess.js";
import { unzipArchive } from "./unzipArchive.js";
import {
@@ -524,9 +524,9 @@ async function ensureLinuxArmBrowser(options?: EnsureBrowserOptions): Promise<Br
}
// Could not auto-install — give clear manual instructions.
throw new Error(
`Chrome Headless Shell is not available for Linux ARM64 (DGX Spark, GB10, Jetson).\n\n` +
`Install Chromium manually and point hyperframes to it:\n\n` +
throw new SetupStepsError(
`Chrome Headless Shell is not available for Linux ARM64 (DGX Spark, GB10, Jetson).`,
`Install Chromium manually and point hyperframes to it:\n\n` +
` sudo apt-get install -y chromium-browser\n` +
` export HYPERFRAMES_BROWSER_PATH=$(which chromium-browser)\n\n` +
`Then re-run your command. The HYPERFRAMES_BROWSER_PATH env var persists for the session.`,
@@ -8,7 +8,12 @@ import { createPartialCaptureState } from "./partialCapture.js";
import { createCaptureDownloadBudget } from "./readBoundedResponse.js";
import { StageBudgetTimeoutError } from "./captureTimeout.js";
const control = vi.hoisted(() => ({ remaining: 10000, expireLazy: false, throwCatalog: false }));
const control = vi.hoisted(() => ({
remaining: 10000,
expireLazy: false,
throwCatalog: false,
styleError: "",
}));
vi.mock("./lazyScrollForCapture.js", () => ({
lazyScrollForCapture: async () => {
if (control.expireLazy) control.remaining = 0;
@@ -35,15 +40,18 @@ vi.mock("./tokenExtractor.js", () => ({
}),
}));
vi.mock("./designStyleExtractor.js", () => ({
extractDesignStyles: async () => ({
typography: [],
spacing: { observed: [], baseUnit: 0 },
radius: [],
shadows: [],
buttons: [],
cards: [],
nav: null,
}),
extractDesignStyles: async () => {
if (control.styleError) throw new Error(control.styleError);
return {
typography: [],
spacing: { observed: [], baseUnit: 0 },
radius: [],
shadows: [],
buttons: [],
cards: [],
nav: null,
};
},
}));
vi.mock("./assetCataloger.js", () => ({ catalogAssets: async () => [] }));
vi.mock("./htmlExtractor.js", () => ({
@@ -71,6 +79,8 @@ afterEach(() => {
control.remaining = 10000;
control.expireLazy = false;
control.throwCatalog = false;
control.styleError = "";
vi.restoreAllMocks();
});
const REFUSED = "Protocol error (Page.captureScreenshot): Unable to capture screenshot";
@@ -184,4 +194,16 @@ describe("core extraction screenshot budget", () => {
"animation catalog evaluate timed out; continuing without animation catalog",
);
});
// fails without the fix: a line break in the reason started a line of its own
it("keeps the reason design styles could not be read on one line", async () => {
const error = vi.spyOn(console, "error").mockImplementation(() => {});
control.styleError = "no styles\n ✓ Captured";
const { warnings } = await extract();
const line = String(error.mock.calls[0]![0]);
expect(line).toMatch(
/^ {2}⚠ Design style extraction failed: no styles\\x0a {2}✓ Captured\\x0a/,
);
expect(line).not.toContain("\n");
expect(warnings.join()).toContain("no styles\n ✓ Captured");
});
});
@@ -28,7 +28,7 @@ import { isDegradableEvaluateTimeoutError } from "./captureTimeout.js";
import { waitForPageReady } from "./navigateForCapture.js";
import { lazyScrollForCapture } from "./lazyScrollForCapture.js";
import { filterExtractedScripts } from "./filterExtractedScripts.js";
import { terminalLines } from "@hyperframes/core";
import { terminalText } from "@hyperframes/core";
export interface CoreExtractionInput {
page1: Page;
@@ -279,7 +279,7 @@ export async function runCoreExtraction(input: CoreExtractionInput): Promise<Cor
} catch (err) {
const errMsg =
err instanceof Error ? `${err.message}\n${err.stack}` : normalizeErrorMessage(err);
console.error(` ⚠ Design style extraction failed: ${terminalLines(errMsg)}`);
console.error(` ⚠ Design style extraction failed: ${terminalText(errMsg)}`);
warnings.push(`Design style extraction failed: ${errMsg}`);
}
};
+30
View File
@@ -50,6 +50,7 @@ const { captureWebsiteMock } = vi.hoisted(() => ({
vi.mock("../capture/index.js", () => ({ captureWebsite: captureWebsiteMock }));
import captureCommand from "./capture.js";
import { SetupStepsError } from "../utils/errorMessage.js";
describe("capture command — vision control", () => {
afterEach(() => {
@@ -528,4 +529,33 @@ describe("capture command: what it prints", () => {
}
expect(printed(error)).toContain("Capture failed: no route\\x0a ✓ Captured");
});
// fails without the fix: the setup commands were joined to the reason with `\x0a`
it("prints the setup commands of a failed capture on lines of their own", async () => {
vi.useFakeTimers();
registerRootExitRequester(() => {});
const error = vi.spyOn(console, "error").mockImplementation(() => {});
const log = vi.spyOn(console, "log").mockImplementation(() => {});
const failure = new SetupStepsError(
"No browser\nhere",
"Install one:\n\n install-it\n use-it",
);
captureWebsiteMock.mockRejectedValueOnce(failure).mockRejectedValueOnce(failure);
const output = mkdtempSync(join(tmpdir(), "hf-capture-steps-"));
const run = (args: object) =>
captureCommand.run!({ args: { url: "https://example.com", output, ...args } } as never).catch(
() => {},
);
try {
await run({});
await run({ json: true });
} finally {
vi.useRealTimers();
rmSync(output, { recursive: true, force: true });
}
expect(printed(error)).toBe(
"\n ✗ Capture failed: No browser\\x0ahere\n\nInstall one:\n\n install-it\n use-it\n",
);
expect(JSON.parse(String(log.mock.calls.at(-1)![0])).error.message).toBe(failure.message);
});
});
+4 -2
View File
@@ -3,7 +3,7 @@ import { failCommand, scheduleCliExit, failUsage } from "../utils/commandResult.
import { defineCommand } from "../utils/defineCommand.js";
import { resolve } from "node:path";
import type { Example } from "./_examples.js";
import { normalizeErrorMessage } from "../utils/errorMessage.js";
import { normalizeErrorMessage, SetupStepsError } from "../utils/errorMessage.js";
import { diag } from "../ui/diagnostics.js";
import type { CapturePhaseProgress } from "../capture/types.js";
import { parseCaptureDeadline } from "../capture/captureWatchdog.js";
@@ -359,7 +359,9 @@ export default defineCommand({
if (isJson) {
console.log(JSON.stringify(jsonFailure("runtime_error", errMsg)));
} else {
console.error(`\n ✗ Capture failed: ${terminalText(errMsg)}\n`);
const setup = err instanceof SetupStepsError ? err : undefined;
console.error(`\n ✗ Capture failed: ${terminalText(setup?.summary ?? errMsg)}\n`);
if (setup) console.error(`${setup.stepsWrittenByCli}\n`);
}
scheduleCliExit(1);
failCommand();
+9
View File
@@ -12,6 +12,15 @@ function namedAfterCrash(message: string): string {
: message;
}
export class SetupStepsError extends Error {
constructor(
readonly summary: string,
readonly stepsWrittenByCli: string,
) {
super(`${summary}\n\n${stepsWrittenByCli}`);
}
}
export function normalizeErrorMessage(error: unknown): string {
if (error instanceof Error) return namedAfterCrash(error.message);
if (typeof error === "string") return error;