feat(errors): add shared user cancellation error - #1986
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## refactor #1986 +/- ##
============================================
- Coverage 96.78% 96.78% -0.01%
============================================
Files 326 326
Lines 18061 18052 -9
============================================
- Hits 17480 17471 -9
Misses 581 581 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Hweinstock
left a comment
There was a problem hiding this comment.
i like the approach! few comments, but I think some could be follow-ups I could help pick up.
| export class RuntimeInvokeResponseError extends AgentCoreCLIError { | ||
| readonly reported = true; | ||
|
|
||
| export class RuntimeInvokeResponseError extends SilentCLIError { |
There was a problem hiding this comment.
why are runtime invoke responses silent? I thought this was the error we get when the stream parsing fails.
| if ((error as Error)?.name === "AbortError") return ExitCode.INTERRUPTED; | ||
| if (caught instanceof AgentCoreCLIError) return caught.exitCode; | ||
| return ExitCode.FAILURE; | ||
| const error = AgentCoreCLIError.fromError(caught); |
There was a problem hiding this comment.
nice, really like how simple this is now!
| error_name: error.name, | ||
| error_source: error.source, | ||
| }); | ||
| if (error.exitCode !== 0) { |
There was a problem hiding this comment.
i wonder if it makes sense to expand the exit_reason attribute to accept a cancelled value. That way we still get telemetry for these cancellations.
could be a follow-up since we'll need to adjust the backend schema to accommodate.
| ); | ||
| // file is written in addition to the normal metadata output | ||
| ctx.require(JsonRendererKey).renderJson({ ...response, filePath }); | ||
| } finally { |
There was a problem hiding this comment.
do we need the same controller.signal.throwIfAborted(); check here?
Also wondering if it makes sense to build an abstraction for this since it seems there's already a few consumers?
Something like:
async function withCancellation<T>(fn: (signal: AbortSignal) => Promise<T>): Promise<T> {
const controller = new AbortController();
const interrupt = () => controller.abort(new UserCancellationError());
process.once("SIGINT", interrupt);
try {
return await fn(controller.signal);
} catch (error) {
controller.signal.throwIfAborted();
throw error;
} finally {
controller.abort();
process.off("SIGINT", interrupt);
}
}
Problem
Commander exits and user cancellations bypass the shared CLI error model. The root runnable unwraps causes and checks raw error names, while Runtime invoke defines a resource-specific interruption error and rewraps cancellation during response handling.
Solution
CommanderErrorinAgentCoreCLIError.fromError, preserving help as exit0and mapping parse failures to usage exit2SilentCLIErrorcategory so only intentionally silent errors skip generic root stderr outputUserCancellationErrorwith exit code130AbortSignal.reasonfor Runtime invoke and dataset download SIGINT handlingAbortErrorhandling unchangedVerification
bun test src/errors/errors.test.tsx src/runnable/index.test.ts src/handlers/runtime/invoke/response.test.ts src/handlers/runtime/invoke/invoke.test.tsx src/handlers/eval/dataset/dataset.test.tsx(97 pass, 0 fail)bun run typecheckbun run lint:checkbun run format:checkbun run buildgit diff --check1110 pass, 0 fail1110 pass, 0 fail1110 pass, 0 fail0, help on stdout, no stderr or error log2, one Commander error line, classified as a user error130, no stdout or stderr, structuredUserCancellationErrorlog