| id | exit-codes | ||||
|---|---|---|---|---|---|
| title | Exit Codes | ||||
| sidebar_label | Exit Codes | ||||
| description | Complete reference of CLI exit codes for error handling in scripts and CI/CD pipelines. | ||||
| doc_type | reference | ||||
| audience | developers, devops engineers | ||||
| tags |
|
Purpose: For automation users, provides complete reference of CLI exit codes for error handling in scripts and CI/CD pipelines.
This reference documents all exit codes returned by openCenter CLI commands.
openCenter CLI uses standard Unix exit codes to indicate command success or failure. Exit codes enable automated error handling in scripts and CI/CD pipelines.
Convention:
0: Success1-255: Error (specific error indicated by code)
Usage in scripts:
#!/bin/bash
opencenter cluster validate my-cluster
if [ $? -eq 0 ]; then
echo "Validation passed"
else
echo "Validation failed with exit code $?"
exit 1
fiCommand completed successfully.
Example:
opencenter cluster validate my-cluster
echo $? # Output: 0When returned:
- Configuration validation passed
- Cluster operation completed successfully
- Command executed without errors
General error or unspecified failure. This is the catch-all exit code for any error condition.
Example:
opencenter cluster validate invalid-cluster
echo $? # Output: 1When returned:
- Configuration validation failed
- Provider authentication failed
- Network connectivity error
- Missing dependencies
- Invalid command syntax
- Missing required arguments
- Any unclassified error
Note: Most error conditions currently return exit code 1. Use --output json on supported commands to get structured error details for programmatic handling.
The specified cluster configuration does not exist.
Example:
opencenter cluster validate nonexistent-cluster
echo $? # Output: 3
# stderr: Check available clusters with: opencenter cluster list
# Initialize a new cluster with: opencenter cluster init nonexistent-clusterWhen returned:
- Cluster name does not match any configuration file
- Organization/cluster path does not exist
Recovery:
# List available clusters
opencenter cluster list
# Initialize the missing cluster
opencenter cluster init <name> --org <org>| Code | Meaning | Typical Cause |
|---|---|---|
| 0 | Success | Command completed without error |
| 1 | General error | Validation failure, provider error, network error, any unclassified error |
| 3 | Config not found | Cluster configuration file does not exist |
#!/bin/bash
set -e # Exit on any error
opencenter cluster validate my-cluster
opencenter cluster generate my-cluster
opencenter cluster deploy my-cluster
echo "Cluster deployed successfully"#!/bin/bash
opencenter cluster validate my-cluster
EXIT_CODE=$?
case $EXIT_CODE in
0)
echo "Validation passed"
;;
3)
echo "Cluster not found - run 'opencenter cluster init' first"
exit 1
;;
*)
echo "Error (exit code: $EXIT_CODE)"
exit 1
;;
esacFor programmatic error handling, use --output json to get structured error details:
#!/bin/bash
OUTPUT=$(opencenter cluster validate my-cluster --output json 2>&1)
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "$OUTPUT" | jq '.errors[]?.message' 2>/dev/null
exit $EXIT_CODE
fi#!/bin/bash
MAX_RETRIES=3
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
opencenter cluster deploy my-cluster
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "Cluster deployed successfully"
exit 0
elif [ $EXIT_CODE -eq 1 ]; then
echo "Error - retrying ($((RETRY_COUNT + 1))/$MAX_RETRIES)"
RETRY_COUNT=$((RETRY_COUNT + 1))
sleep 30
else
echo "Non-retryable error (exit code: $EXIT_CODE)"
exit $EXIT_CODE
fi
done
echo "Failed after $MAX_RETRIES retries"
exit 1GitHub Actions:
- name: Validate cluster
run: opencenter cluster validate my-cluster
continue-on-error: false
- name: Deploy cluster
run: opencenter cluster deploy my-cluster
if: success()GitLab CI:
validate:
script:
- opencenter cluster validate my-cluster
allow_failure: false
deploy:
script:
- opencenter cluster deploy my-cluster
needs: [validate]
when: on_successJenkins:
stage('Validate') {
steps {
script {
def exitCode = sh(
script: 'opencenter cluster validate my-cluster',
returnStatus: true
)
if (exitCode != 0) {
error("Validation failed with exit code ${exitCode}")
}
}
}
}# Run command
opencenter cluster validate my-cluster
# Check exit code
echo $?
# Or save to variable
EXIT_CODE=$?
echo "Exit code: $EXIT_CODE"# If statement
if opencenter cluster validate my-cluster; then
echo "Validation passed"
else
echo "Validation failed"
fi
# Or with explicit check
opencenter cluster validate my-cluster
if [ $? -eq 0 ]; then
echo "Validation passed"
fi# Run multiple commands, check each
opencenter cluster validate my-cluster
VALIDATE_EXIT=$?
opencenter cluster generate my-cluster
SETUP_EXIT=$?
if [ $VALIDATE_EXIT -eq 0 ] && [ $SETUP_EXIT -eq 0 ]; then
echo "All commands succeeded"
else
echo "One or more commands failed"
echo "Validate exit code: $VALIDATE_EXIT"
echo "Setup exit code: $SETUP_EXIT"
exit 1
fiExit codes are accompanied by error messages on stderr:
# Redirect stderr to file
opencenter cluster validate my-cluster 2> error.log
# Check exit code and error message
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "Command failed with exit code $EXIT_CODE"
echo "Error message:"
cat error.log
fi- Always check exit codes: Don't assume commands succeed
- Use set -e in scripts: Exit on first error
- Handle specific errors: Different actions for different exit codes
- Log exit codes: Record exit codes for debugging
- Retry transient errors: Network errors (exit code 4) can be retried
- Don't retry permanent errors: Configuration errors (exit code 2) need fixing
- Document expected exit codes: In scripts and CI/CD pipelines
- Test error paths: Verify error handling works correctly
Symptom: Command returns unexpected exit code
Diagnosis:
# Run command with verbose output
opencenter cluster validate my-cluster --verbose
# Check error message
opencenter cluster validate my-cluster 2>&1 | tee error.log
# Check exit code
echo $?Solution:
- Read error message carefully
- Check command syntax
- Verify configuration file
- Check provider credentials
Symptom: Command returns 0 but didn't complete successfully
Diagnosis:
# Check command output
opencenter cluster validate my-cluster | tee output.log
# Verify expected output
grep "Configuration is valid" output.logSolution:
- Check command output for warnings
- Verify expected behavior
- Report bug if exit code incorrect
Symptom: Script exits without completing
Diagnosis:
# Run script with set -x for debugging
bash -x script.sh
# Check which command failed
echo $?Solution:
# Use set -e to exit on error
set -e
# Or handle errors explicitly
opencenter cluster validate my-cluster || {
echo "Validation failed"
exit 1
}- CLI Commands - Complete command reference
- Integrate CI/CD - CI/CD integration
- Troubleshoot Deployment - Debug errors
This reference is based on:
- Exit code conventions: Unix/Linux standards
- CLI error handling:
cmd/directory structure - Error types:
internal/config/validator.go,internal/cloud/ - CI/CD integration: Session 7 integrate-ci-cd.md