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
| Code | Meaning | Example |
|---|---|---|
0 | Success | Command completed successfully |
1 | Generic error | Unexpected failure, network error, or unknown issue |
2 | Usage error | Invalid flags, missing required arguments, or malformed command |
3 | Authentication failure | Missing credentials, invalid API key, or permission denied |
4 | Resource not found | App, build, or resource does not exist |
5 | Conflict | Resource already exists or version conflict |
HTTP Status Mapping
The CLI maps HTTP status codes to exit codes:4xx Client Errors
Formula:10 + (status - 400)
| HTTP Status | Exit Code | Description |
|---|---|---|
| 400 Bad Request | 10 | Invalid request parameters |
| 401 Unauthorized | 11 | Authentication required |
| 403 Forbidden | 12 | Permission denied |
| 404 Not Found | 4 | Resource not found (special case) |
| 409 Conflict | 5 | Resource conflict (special case) |
| 422 Unprocessable | 22 | Validation error |
5xx Server Errors
Formula:60 + (status - 500)
| HTTP Status | Exit Code | Description |
|---|---|---|
| 500 Internal Server Error | 60 | API server error |
| 502 Bad Gateway | 62 | Gateway error |
| 503 Service Unavailable | 63 | Service temporarily unavailable |
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:Well-Known Error Codes
The CLI recognizes standard App Store Connect error codes:NOT_FOUND→ Exit code4CONFLICT→ Exit code5UNAUTHORIZED→ Exit code3FORBIDDEN→ Exit code3BAD_REQUEST→ Exit code10
Associated Errors
Some API errors include additional details undermeta.associatedErrors:
Error Messages
All error messages go to stderr, not stdout: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
Permission Denied
Debugging Errors
Enable debug logging with--debug or --api-debug:
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.Related
- Authentication - Set up API credentials
- Workflows - Error handling in multi-step workflows
- Exit Codes Reference - Source code