Skip to content

refactor(errors): migrate input validation errors to use the modeled exception. - #1848

Open
Hweinstock wants to merge 4 commits into
aws:refactorfrom
Hweinstock:feat/input-validation
Open

refactor(errors): migrate input validation errors to use the modeled exception. #1848
Hweinstock wants to merge 4 commits into
aws:refactorfrom
Hweinstock:feat/input-validation

Conversation

@Hweinstock

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #1834.

We defined the common errors, but we aren't using the modeled exceptions anywhere.

Solution

Migrate input validation errors to use the shared input validation error.

Notes

  • there are other errors we can migrate as well to new modeled exceptions, but keep the PR scope minimal and focused.

Testing

Ran the CLI to verify this error is now classified correctly and logged at the root handler:

{"level":"error","msg":"","time":1785252586823,"cliSessionId":"ef345869-50c2-41ec-b282-f7d5d4044ece","error":{"name":"InputValidationError","message":"Invalid value for argu
ment 'key': Invalid option: expected one of \"telemetry\"|\"telemetry.enabled\"|\"telemetry.audit\"|\"telemetry.endpoint\"|\"installationId\"","stack":"{...}","exitCode":1,"meta":{},"source":"user"}}

@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label Jul 28, 2026
@codecov-commenter

codecov-commenter commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.29126% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.90%. Comparing base (ccd4024) to head (6aa8a73).
⚠️ Report is 1 commits behind head on refactor.

Files with missing lines Patch % Lines
src/handlers/config/handler.tsx 28.57% 5 Missing ⚠️
...ntity/api-key-credential-provider/update/index.tsx 66.66% 4 Missing ⚠️
src/handlers/utils.tsx 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           refactor    #1848      +/-   ##
============================================
- Coverage     94.92%   94.90%   -0.02%     
============================================
  Files           155      155              
  Lines          7565     7615      +50     
============================================
+ Hits           7181     7227      +46     
- Misses          384      388       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Jul 28, 2026
@Hweinstock
Hweinstock marked this pull request as ready for review July 28, 2026 15:38

@aidandaly24 aidandaly24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, let me know what you think.

Comment thread src/router/flags.tsx
const result = flag.schema.safeParse(coerce(flag.schema, opts[attributeName(flag.name)]));
if (!result.success) {
throw new TypeError(
throw new InputValidationError(

@aidandaly24 aidandaly24 Jul 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could we update the existing invalid-flag router test to assert InputValidationError, matching the new config assertions? It currently checks only the message and passed when this path threw TypeError, so the shared flag-classification change is otherwise untested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good call, I like asserting on type rather than message since it avoids coupling with the exact message.

);
}

const resolver = new SourceResolver({ stdin: io.stdin });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One input-validation path appears to be missing from this migration the SourceResolutionError in src/io/source.ts still extends TypeError. Missing file:// sources and invalid UTF-8 therefore continue to be classified as internal. Could it extend InputValidationError, with a regression test asserting source: "user"? I also get it if you think this is better as a separate PR. I think this may have been because I was working on the SourceResolver at the same time as you were creating the AgentCore Error.

@jariy17 jariy17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good but u missed:

  • accessor.tsx:80
  • SourceResolutionError (io/source.ts:13)
  • tui/index.tsx:46

@Hweinstock

Copy link
Copy Markdown
Contributor Author

accessor.tsx:80
SourceResolutionError (io/source.ts:13)
tui/index.tsx:46

Migrated the source resolution, but the other two I think deserve their own errors.

private async writeToConfigFile(data: GlobalConfigFileData): Promise<GlobalConfigFileData> {
const dataParseResult = globalConfigFileSchema.safeParse(data);
if (!dataParseResult.success) {
// TODO: mark this as a client-source error.
throw new TypeError(z.prettifyError(dataParseResult.error));
}
await this.json.write(this.filePath, dataParseResult.data);
return data;
}
This error occurs when we write global config back out to the file and it fails zod validation. This should only happen if our zod schema is out of sync with the type in the signature, or we cast somewhere internally, so I don't think we want to mark it as a user error.

I also think:

if (!io.stdin.isTTY || !io.stdout.isTTY) {
throw new TypeError("interactive mode requires a TTY on stdin and stdout");
}

might be better classified as an error to signify there is something wrong with the users environment rather than that they provided invalid input. However, I do think user error is right here.

I can look into adding custom error types for these two as a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants