fix(errors): define new custom errors for failures. - #1868
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## refactor #1868 +/- ##
=========================================
Coverage 95.00% 95.01%
=========================================
Files 161 161
Lines 7691 7699 +8
=========================================
+ Hits 7307 7315 +8
Misses 384 384 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e196889 to
ae27e06
Compare
| } | ||
|
|
||
| /** Error raised by invalid data coming from internal sources **/ | ||
| export class InternalValidationError extends AgentCoreCLIError { |
There was a problem hiding this comment.
note: I intentionally defined these in the local files since they aren't used elsewhere. I think we can lift these up when we see an opportunity to generalize. I want to avoid lifting this up now, then trying to force these usages elsewhere.
There was a problem hiding this comment.
Makes sense to me, that's the only concern I could see from this PR.
aidandaly24
left a comment
There was a problem hiding this comment.
Approved, I'd definitely extract the error to the common errors location when we see more use cases.
| throw new InternalValidationError("failed to validate config data before writing to file", { | ||
| cause: dataParseResult.error, | ||
| }); |
There was a problem hiding this comment.
One small nit comment, let me know what you think.
This path is reachable from CLI input, not only internal data. I ran agentcore config telemetry '{"enabled":"nope"}'. Then the config handler parses that object and casts it to GlobalConfig, then this logs InternalValidationError with source: "internal". I feel like the handler should probably validate the updated config as user input and throw InputValidationError. Not a blocker or anything but just a thought.
There was a problem hiding this comment.
yeah thats a good point. I think this could be a user or internal error depending on how its reached, but we shouldn't make an internal error so easy to trigger. Also, I ran the same case you described and it produced a worse customer error message so let me actually swap this to InputValidationError. good catch!
Problem
There are a few errors that are not yet migrated to the custom errors types. This PR does not aim to migrate all of them, but migrates a few that were raised in a previous PR.
#1848 (comment)
Solution
InputValidationErrorfor when data passed internally fails validation in the config.invalidEnvironmentErrorfor when tty is missing on stdin and stdout.Testing