Skip to content

Add structured exit codes for different failure categories #11

Description

@aidandaly24

Problem

The CLI currently exits with generic exit code 1 for all failures. This makes it hard to programmatically distinguish between different failure types in CI/CD pipelines or scripts that wrap agentcore commands.

Proposed Solution

Define and export named exit codes in src/cli/errors.ts (or a new src/cli/exit-codes.ts) that map to specific failure categories:

Exit Code Constant Meaning
0 EXIT_SUCCESS Command succeeded
1 EXIT_GENERAL_ERROR Unknown/unhandled error
2 EXIT_INVALID_ARGS Invalid CLI arguments or missing required flags
3 EXIT_AUTH_EXPIRED AWS credentials expired or invalid (maps to EXPIRED_TOKEN_ERROR_CODES in errors.ts)
4 EXIT_ACCESS_DENIED IAM permission error (maps to isAccessDeniedError())
5 EXIT_AGENT_NOT_FOUND Requested agent doesn't exist
6 EXIT_DEPLOY_FAILED Deployment/CloudFormation failure

Requirements

  • Export a ExitCode enum or const object from src/cli/exit-codes.ts
  • Update getErrorMessage() flow or add a getExitCode(err: unknown): number function that maps errors to the correct exit code
  • Update the top-level CLI error handler (likely in src/cli/cli.ts or src/cli/index.ts) to use the mapped exit code instead of hardcoded process.exit(1)
  • Add unit tests in src/cli/__tests__/ for the exit code mapping

Acceptance Criteria

  • Exit codes enum/object exported from new file
  • getExitCode() correctly maps isAccessDeniedError()EXIT_ACCESS_DENIED
  • getExitCode() correctly maps expired token errors → EXIT_AUTH_EXPIRED
  • Top-level error handler uses getExitCode() instead of hardcoded 1
  • Unit tests cover all exit code mappings
  • Unknown errors default to EXIT_GENERAL_ERROR (1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions