feat(errors): add top-level errors module for definitions and classification. - #1834
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## refactor #1834 +/- ##
============================================
+ Coverage 94.89% 94.91% +0.02%
============================================
Files 151 154 +3
Lines 7421 7455 +34
============================================
+ Hits 7042 7076 +34
Misses 379 379 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
audit fail is fixed in github.com//pull/1833 |
| .child({ errorName: error.name, errorMessage: error.message, stack: error.stack ?? "" }) | ||
| .error(); | ||
| throw e; | ||
| const error = classify(e); |
There was a problem hiding this comment.
we classify here, instead of the top-level since we'll have the telemetry client in scope here, but not at the top-level.
| if (ServiceException.isInstance(error)) { | ||
| const httpStatusCode = error.$metadata.httpStatusCode; | ||
| const source = | ||
| httpStatusCode !== undefined && httpStatusCode >= 400 && httpStatusCode < 500 |
There was a problem hiding this comment.
Any chance something like 429: ThrottlingException shows up here? Just thinking about 400s that might not truly be user errors.
There was a problem hiding this comment.
Yeah good question. If the CLI sees a throttling exception its difficult to know if its an issue on the CLI making too many requests, or a user spamming through the CLI.
We don't want any internal faults to be user-trigger-able, so I believe its safer to make this a user error and maintain the error name in telemetry. That way if we see a bunch of throttling across the board, we know there is likely a bug on the CLI.
AlexanderRichey
left a comment
There was a problem hiding this comment.
Looks good! One thing I think would be a bit nicer would be not to have classify but to have an alternative constructor for this case that would do the same thing:
const error = AgentCoreCLIError.fromError(e)This would keep all of the public error handling code neatly exposed through one class.
Second thing is getting rid of UNKNOWN as an error type in favor of INTERNAL.
| .child({ errorName: error.name, errorMessage: error.message, stack: error.stack ?? "" }) | ||
| .error(); | ||
| throw e; | ||
| const error = classify(e); |
There was a problem hiding this comment.
I wonder if an alternative constructor would be more elegant here. Something like this?
const error = AgentCoreCLIError.fromError(e)There was a problem hiding this comment.
I like it! I'll swap it over.
| INTERNAL: "internal", | ||
| USER: "user", | ||
| SERVICE: "service", | ||
| UNKNOWN: "unknown", |
There was a problem hiding this comment.
Can we get rid of UNKNOWN? It doesn't seem meaningfully different from INTERNAL, unless I'm missing something.
There was a problem hiding this comment.
discussed offline. distinction doesn't justify a separate field, aligning on INTERNAL.
a01d565 to
ddc8536
Compare
Problem
See #1790
There is no consistent format for custom errors or way to override the exitCode.
Solution
Define a top level errors module that has exposes two pieces of functionality:
AgentCoreCLIErrorto build new errors from, that accepts metadata and "source" (used in telemetry).classifyfunction that takes an arbitary value at the top-level and turns it into the correct error (with support for common AWS SDK exceptions).Verification
Notes
this PR sets up the infrastructure, but there are more call sites to migrate. Migrating will come as a follow-up to keep the PR small and avoid churn with other open PRs.