Skip to main content

Error Handling

Understand CLI exit codes, API errors, and how to handle failures in scripts and CI/CD pipelines.
The CLI provides structured error handling with predictable exit codes following CI/CD best practices.

Exit Codes

Every command returns a numeric exit code that indicates the result:

Exit Code Reference

HTTP Status Mapping

The CLI maps HTTP status codes to exit codes:

4xx Client Errors

Formula: 10 + (status - 400)

5xx Server Errors

Formula: 60 + (status - 500)
Exit codes follow a deterministic formula defined in cmd/exit_codes.go. This ensures consistent, scriptable error handling.

API Errors

The App Store Connect API returns structured error responses:
The CLI parses these errors and displays them in a human-readable format:

Well-Known Error Codes

The CLI recognizes standard App Store Connect error codes:
  • NOT_FOUND → Exit code 4
  • CONFLICT → Exit code 5
  • UNAUTHORIZED → Exit code 3
  • FORBIDDEN → Exit code 3
  • BAD_REQUEST → Exit code 10
These map to Go error sentinels:

Associated Errors

Some API errors include additional details under meta.associatedErrors:
The CLI formats these errors with clear indentation and grouping.

Error Messages

All error messages go to stderr, not stdout:
This allows safe piping and redirection:

Handling Errors in Scripts

Exit Code Checks

Specific Error Handling

Retry on Transient Errors

CI/CD Integration

GitHub Actions

GitLab CI

Makefile

Authentication Errors

Common authentication failures and solutions:

Missing Credentials

Missing credentials return exit code 1, not 3. Exit code 3 is reserved for failed authentication (invalid credentials), not missing credentials.

Invalid API Key

Solution: Verify your credentials:

Permission Denied

Solution: Check your App Store Connect role and permissions.

Debugging Errors

Enable debug logging with --debug or --api-debug:
Debug output goes to stderr:

Environment Variables

Error Handling Best Practices

Always Check Exit Codes

Use set -e in shell scripts or check $? after each command.

Separate stdout and stderr

Redirect errors to a log file: asc apps list 2> errors.log.

Handle Expected Errors

Exit code 4 (not found) is often expected. Handle it explicitly.

Retry Transient Errors

Retry on exit codes 60-99 (5xx server errors) with exponential backoff.