Exit Code Overview
Check Image uses three exit codes to communicate validation results and execution status:| Exit Code | Status | Meaning |
|---|---|---|
| 0 | Success | Validation passed or no checks were run |
| 1 | Validation Failed | Image did not meet validation requirements |
| 2 | Execution Error | Tool encountered an error during execution |
Exit Code Semantics
Exit 0 - Success
Returned when:- All validation checks passed successfully
- No checks were run (
ValidationSkippedstate) - All requested checks are explicitly skipped via
--skip
Exit 1 - Validation Failed
Returned when:- Image does not meet validation criteria
- One or more checks fail validation
- Image violates security or operational standards
Exit 2 - Execution Error
Returned when:- Image not found in registry or local daemon
- Invalid configuration file syntax
- Missing required flags or arguments
- Policy file format errors
- Authentication failures
- Network connectivity issues
- Invalid regular expressions in label patterns
Precedence in all Command
When running multiple checks with the all command, exit code precedence determines the final result:
Precedence Order (highest to lowest):
- Exit 2 - Execution Error (
ExecutionError) - Exit 1 - Validation Failed (
ValidationFailed) - Exit 0 - Validation Succeeded (
ValidationSucceeded) - Exit 0 - Validation Skipped (
ValidationSkipped)
How Precedence Works
Scenario 1: Mixed Results If some checks fail validation and others pass:Implementation Details
The precedence is enforced by theValidationResult type in cmd/check-image/commands/root.go:
UpdateResult() function ensures the global Result variable always reflects the highest-priority outcome.
Shell Scripting Examples
Basic Exit Code Handling
CI/CD Pipeline Example
Multiple Check Strategy
Parallel Validation
Soft Failure with Logging
Fail-Fast vs Continue-on-Error
ValidationResult States
The internalValidationResult enum represents check outcomes:
State Transitions in all Command
Result Update Logic
TheUpdateResult() helper in root.go ensures correct precedence:
- Initial:
ValidationSkipped(0) - First check passes:
ValidationSucceeded(1) — higher priority - Second check fails:
ValidationFailed(2) — higher priority - Third check errors:
ExecutionError(3) — highest priority - Final exit code: 2 (ExecutionError)
Best Practices
1. Always Check Exit Codes
2. Distinguish Validation Failures from Errors
3. Use JSON Output for Detailed Analysis
4. Set Appropriate CI/CD Exit Behavior
Next Steps
Policy Configuration
Learn about policy file structure and validation rules
Troubleshooting
Common issues and solutions