Skip to content

refactor: centralize error types for consistent definition shapes#1238

Open
Hweinstock wants to merge 3 commits into
aws:mainfrom
Hweinstock:refactor/error-categories
Open

refactor: centralize error types for consistent definition shapes#1238
Hweinstock wants to merge 3 commits into
aws:mainfrom
Hweinstock:refactor/error-categories

Conversation

@Hweinstock
Copy link
Copy Markdown
Contributor

@Hweinstock Hweinstock commented May 13, 2026

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

  • All error classes now live in src/lib/errors/types.ts
  • Every error carries its source ('user' | 'client' | 'service' | 'unknown') as a constructor parameter with a sensible default. Callers can override per throw site.
  • The telemetry client reads errorSource and name directly from BaseError instances.
  • A small name-based map in src/cli/telemetry/error.ts handles AWS SDK exceptions that bubble up untyped.
  • Each error class has its own entry in ErrorName.

Adding a new error (2 steps)

  1. Define class in src/lib/errors/types.ts extending BaseError
  2. Add its name to ErrorName enum in src/cli/telemetry/schemas/common-shapes.ts

(added to AGENTS.md)

Related Issue

N/A — internal cleanup

Documentation PR

N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe): Error architecture refactoring + telemetry classification simplification

Testing

How have you tested the change?

  • I ran npm run test:unit and npm run test:integ
  • I ran npm run typecheck
  • I ran npm run lint
  • If I modified src/assets/, I ran npm run test:update-snapshots and committed the updated snapshots

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added the size/m PR size: M label May 13, 2026
@Hweinstock Hweinstock changed the title refactor: align telemetry ErrorCategory with actual error classes refactor: align telemetry ErrorCategory with used error classes May 13, 2026
@github-actions github-actions Bot added the agentcore-harness-reviewing AgentCore Harness review in progress label May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.13.1.tgz

How to install

npm install https://github.com/aws/agentcore-cli/releases/download/pr-1238-tarball/aws-agentcore-0.13.1.tgz

Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/cli/telemetry/error-classification.ts Outdated
Comment thread src/cli/telemetry/error-classification.ts Outdated
@github-actions github-actions Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label May 13, 2026
@Hweinstock
Copy link
Copy Markdown
Contributor Author

Based on feedback, there is some inconsistency across the codebase for how errors are defined. Going to attempt to centralize this.

@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from d90fe09 to 114ea1b Compare May 13, 2026 20:10
@github-actions github-actions Bot added size/l PR size: L and removed size/m PR size: M labels May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from 114ea1b to 52fc5a9 Compare May 13, 2026 20:26
@github-actions github-actions Bot removed the size/l PR size: L label May 13, 2026
@github-actions github-actions Bot added the size/l PR size: L label May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch 2 times, most recently from f19fd20 to d848ee9 Compare May 13, 2026 20:39
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from d848ee9 to 77fb3f2 Compare May 13, 2026 20:41
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from 77fb3f2 to e771ccc Compare May 13, 2026 20:46
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from e771ccc to acb64b9 Compare May 13, 2026 20:52
@github-actions github-actions Bot added the size/l PR size: L label May 13, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from 81181ce to 4bb4a35 Compare May 13, 2026 21:15
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 13, 2026
@Hweinstock Hweinstock closed this May 13, 2026
@Hweinstock Hweinstock reopened this May 13, 2026
@github-actions github-actions Bot added size/l PR size: L agentcore-harness-reviewing AgentCore Harness review in progress and removed size/l PR size: L labels May 13, 2026
Copy link
Copy Markdown

@agentcore-cli-automation agentcore-cli-automation left a comment

Choose a reason for hiding this comment

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

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.)

Comment thread AGENTS.md
Comment thread src/cli/telemetry/error.ts Outdated
Comment thread src/cli/telemetry/__tests__/client.test.ts
@github-actions github-actions Bot added size/l PR size: L and removed agentcore-harness-reviewing AgentCore Harness review in progress size/l PR size: L labels May 13, 2026
@Hweinstock Hweinstock changed the title refactor: align telemetry ErrorCategory with used error classes refactor: centralize error types for consistent definition shapes May 13, 2026
@Hweinstock Hweinstock marked this pull request as ready for review May 13, 2026 21:31
@Hweinstock Hweinstock requested a review from a team May 13, 2026 21:32
…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)
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from de950e4 to ea99b26 Compare May 14, 2026 18:45
@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels May 14, 2026
@Hweinstock Hweinstock force-pushed the refactor/error-categories branch from ea99b26 to cac2559 Compare May 14, 2026 18:50
ConflictException/ResourceAlreadyExistsException are user-fixable
conditions (duplicate names, unresolved references), matching the
ConflictError class default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants