Skip to content

Commit 590e105

Browse files
committed
refactor: ensure errors with dynamic logging are not swallowed
Ensures errors printed with dynamic logging are not swallowed. This is easily confusing as the report summary is currently just printed with e.g. zero completed app generations.
1 parent 5c8532a commit 590e105

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"build-runner": "tsc",
66
"release-build": "tsx release-build.ts",
77
"web-codegen-scorer": "tsx ./runner/bin/cli.ts",
8+
"wcs": "pnpm -s web-codegen-scorer",
89
"eval": "pnpm web-codegen-scorer eval",
910
"init": "pnpm web-codegen-scorer init",
1011
"report": "cd report-app && CODEGEN_REPORTS_DIR=../.web-codegen-scorer/reports pnpm start",

runner/eval-cli.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ function builder(argv: Argv): Argv<Options> {
119119
})
120120
.option('logging', {
121121
type: 'string',
122-
default: 'dynamic' as const,
122+
default:
123+
process.env['CI'] === '1'
124+
? ('text-only' as const)
125+
: ('dynamic' as const),
126+
defaultDescription: '`dynamic` (or `text-only` when `CI=1`)',
127+
requiresArg: true,
123128
choices: ['text-only', 'dynamic'] as const,
124129
description: 'Type of logging to use during the evaluation process',
125130
})

runner/orchestration/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ export async function generateCodeAndAssess(options: {
175175
stack: e instanceof Error ? e.stack : undefined,
176176
});
177177

178-
let details = ` Error: ${e}`;
178+
let details = `Error: ${e}`;
179179
if (e instanceof Error && e.stack) {
180-
details += e.stack;
180+
details += `\nStack: ${e.stack}`;
181181
}
182182

183183
progress.log(

runner/progress/dynamic-progress-logger.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ProgressType,
77
progressTypeToIcon,
88
} from './progress-logger.js';
9+
import { redX } from '../reporting/format.js';
910

1011
const PREFIX_WIDTH = 20;
1112

@@ -17,6 +18,11 @@ export class DynamicProgressLogger implements ProgressLogger {
1718
private spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
1819
private currentSpinnerFrame = 0;
1920
private spinnerInterval: ReturnType<typeof setInterval> | undefined;
21+
private errors: {
22+
prompt: RootPromptDefinition;
23+
message: string;
24+
details?: string;
25+
}[] = [];
2026

2127
initialize(total: number): void {
2228
this.finalize();
@@ -72,9 +78,22 @@ export class DynamicProgressLogger implements ProgressLogger {
7278
this.wrapper?.stop();
7379
this.pendingBars.clear();
7480
this.wrapper = this.totalBar = this.spinnerInterval = undefined;
81+
82+
for (const error of this.errors) {
83+
let message = `${redX()} [${error.prompt.name}] ${error.message}`;
84+
if (error.details) {
85+
message += `\n ${error.details}`;
86+
}
87+
console.error(message);
88+
}
7589
}
7690

77-
log(prompt: RootPromptDefinition, type: ProgressType, message: string): void {
91+
log(
92+
prompt: RootPromptDefinition,
93+
type: ProgressType,
94+
message: string,
95+
details?: string
96+
): void {
7897
if (!this.wrapper || !this.totalBar) {
7998
return;
8099
}
@@ -92,6 +111,11 @@ export class DynamicProgressLogger implements ProgressLogger {
92111
return;
93112
}
94113

114+
// Capture errors for static printing once the dynamic progress is hidden.
115+
if (type === 'error') {
116+
this.errors.push({ prompt, message, details });
117+
}
118+
95119
// Pad/trim the name so they're all the same length.
96120
const name = this.trimString(
97121
prompt.name.padEnd(PREFIX_WIDTH, ' '),

0 commit comments

Comments
 (0)