refactor: centralize error types for consistent definition shapes#1238
refactor: centralize error types for consistent definition shapes#1238Hweinstock wants to merge 3 commits into
Conversation
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-1238-tarball/aws-agentcore-0.13.1.tgz |
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Thanks for the cleanup — switching from string matching to instanceof against real classes is a nicer model. However, this PR drops a large number of error categories that are actively thrown in the codebase, which will noticeably degrade telemetry signal in production. Flagging two issues that I think need to be addressed before merging; details inline.
Separately (non-blocking, your call): there's now a semantic inconsistency where AgentAlreadyExistsError is a user error but ConflictError (e.g., "endpoint already exists" thrown from RuntimeEndpointPrimitive) is not, even though they describe the same kind of situation. Worth aligning.
|
Based on feedback, there is some inconsistency across the codebase for how errors are defined. Going to attempt to centralize this. |
d90fe09 to
114ea1b
Compare
114ea1b to
52fc5a9
Compare
f19fd20 to
d848ee9
Compare
d848ee9 to
77fb3f2
Compare
77fb3f2 to
e771ccc
Compare
e771ccc to
acb64b9
Compare
81181ce to
4bb4a35
Compare
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Nice cleanup overall — the BaseError + errorSource model is much clearer than the previous string-name table, and consolidating into one file and one ErrorName enum will make this easier to maintain. Three things I think need to change before merging; details inline.
(The two earlier review comments on error-classification.ts were against a previous version of the PR and have been substantially addressed by the rewrite — most of the missing classes are now in ErrorName, and an SDK fallback map is back in error.ts.)
…r-classification - Add BaseError abstract class with errorSource: 'user' | 'client' | 'service' - All error classes extend BaseError with their source baked in - Move error classes from 5 scattered files into src/lib/errors/types.ts - Delete src/lib/errors/config.ts, src/lib/packaging/errors.ts - Extract Zod formatting helpers into src/lib/errors/zod.ts - Delete src/cli/telemetry/error-classification.ts entirely - Extract classifyError into src/cli/telemetry/error.ts - Classification reads errorSource directly from BaseError instances - SDK name-based fallback map for AWS exceptions - Replace is_user_error boolean with error_source enum in telemetry schema - Preserve PackagingError hierarchy (subclasses extend PackagingError)
de950e4 to
ea99b26
Compare
ea99b26 to
cac2559
Compare
ConflictException/ResourceAlreadyExistsException are user-fixable conditions (duplicate names, unresolved references), matching the ConflictError class default.
Description
Problem
Error definitions are scattered across 5+ files with no consistent structure. The telemetry error classification relied on error being defined a specific way, but this wasn't always true. Adding a new error required updating multiple files and remembering to register it in classification sets.
Solution
src/lib/errors/types.ts'user' | 'client' | 'service' | 'unknown') as a constructor parameter with a sensible default. Callers can override per throw site.errorSourceandnamedirectly fromBaseErrorinstances.src/cli/telemetry/error.tshandles AWS SDK exceptions that bubble up untyped.ErrorName.Adding a new error (2 steps)
src/lib/errors/types.tsextendingBaseErrorErrorNameenum insrc/cli/telemetry/schemas/common-shapes.ts(added to AGENTS.md)
Related Issue
N/A — internal cleanup
Documentation PR
N/A
Type of Change
Testing
How have you tested the change?
npm run test:unitandnpm run test:integnpm run typechecknpm run lintsrc/assets/, I rannpm run test:update-snapshotsand committed the updated snapshotsChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.