Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,36 @@ export async function stopCommand(options: StopOptions): Promise<void> {
}

// Step 6: Count errors
// Uncaught page errors, as reported by agent-browser's `errors` command.
const consoleErrorLines = consoleErrors
.split('\n')
.filter((l) => l.trim() && l.trim() !== 'No errors');
const consoleErrorCount = consoleErrorLines.length > 0 && consoleErrors.trim() !== '' ? consoleErrorLines.length : 0;
// Also count console.error output. Modern apps catch most failures and
// report them via console.error (fetch failures, error boundaries, caught
// exceptions), so counting only uncaught errors under-reports the very
// thing the summary labels "Console errors".
// Primary source: timestamped entries. Fallback: the raw console output,
// in case `console --json` was unavailable or returned an unexpected shape.
let loggedErrorLines = consoleEntries
.filter((e) => e.text.startsWith('[error]'))
.map((e) => e.text);
if (loggedErrorLines.length === 0 && consoleOutput.trim()) {
loggedErrorLines = consoleOutput.split('\n').filter((l) => l.startsWith('[error]'));
}
// Dedupe on normalized text so "Error: X" (uncaught) and "[error] Error: X"
// (console entry for the same error) are not double-counted.
const normalize = (l: string) => l.replace(/^\[error\]\s*/, '').trim();
const seenErrors = new Set<string>();
const allConsoleErrorLines: string[] = [];
for (const line of [...consoleErrorLines, ...loggedErrorLines]) {
const key = normalize(line);
if (key && !seenErrors.has(key)) {
seenErrors.add(key);
allConsoleErrorLines.push(line);
}
}
const consoleErrorCount = allConsoleErrorLines.length;
const consoleErrorsReport = allConsoleErrorLines.join('\n');

// Extract errors from server log using multi-language patterns
const serverErrorLines = extractServerErrors(serverLog);
Expand All @@ -158,7 +184,7 @@ export async function stopCommand(options: StopOptions): Promise<void> {
port: session.port,
videoPath: session.videoPath,
screenshots,
consoleErrors,
consoleErrors: consoleErrorsReport,
consoleErrorCount,
serverLog,
serverErrorCount,
Expand Down Expand Up @@ -241,11 +267,11 @@ export async function stopCommand(options: StopOptions): Promise<void> {
if (consoleErrorCount > 0) {
console.log('');
console.log(chalk.red.bold('Console Errors:'));
for (const line of consoleErrorLines.slice(0, 10)) {
for (const line of allConsoleErrorLines.slice(0, 10)) {
console.log(chalk.red(` ${line}`));
}
if (consoleErrorLines.length > 10) {
console.log(chalk.dim(` ... and ${consoleErrorLines.length - 10} more (see SUMMARY.md)`));
if (allConsoleErrorLines.length > 10) {
console.log(chalk.dim(` ... and ${allConsoleErrorLines.length - 10} more (see SUMMARY.md)`));
}
}

Expand Down