Exit Codes
NextDNS Blocker uses standard exit codes to indicate success or failure, enabling scripting and automation.
Exit Code Summary
Section titled “Exit Code Summary”| Code | Name | Description |
|---|---|---|
| 0 | Success | Command completed successfully |
| 1 | General Error | Unspecified error |
| 2 | Configuration Error | Invalid or missing configuration |
| 3 | API Error | NextDNS API communication failed |
| 4 | Validation Error | Input validation failed |
| 5 | Permission Error | Insufficient permissions |
| 130 | Interrupted | User interrupted (Ctrl+C) |
Detailed Descriptions
Section titled “Detailed Descriptions”0 - Success
Section titled “0 - Success”Command completed without errors.
nextdns-blocker config pushecho $? # Returns: 01 - General Error
Section titled “1 - General Error”An unspecified error occurred.
Common causes:
- Unexpected exception
- Unknown command
- Missing required argument
nextdns-blocker unknown-commandecho $? # Returns: 12 - Configuration Error
Section titled “2 - Configuration Error”Configuration file is invalid or missing.
Common causes:
config.jsonsyntax error- Missing required fields
.envfile not found- Missing API credentials
# With invalid confignextdns-blocker config pushecho $? # Returns: 23 - API Error
Section titled “3 - API Error”Communication with NextDNS API failed.
Common causes:
- Invalid API key
- Invalid profile ID
- Network timeout
- Rate limit exceeded
- NextDNS service unavailable
# With wrong API keynextdns-blocker config pushecho $? # Returns: 34 - Validation Error
Section titled “4 - Validation Error”Input validation failed.
Common causes:
- Invalid domain format
- Invalid time format
- Unknown day name
- Invalid duration format
# With invalid domainnextdns-blocker unblock "not a domain"echo $? # Returns: 45 - Permission Error
Section titled “5 - Permission Error”Insufficient file permissions.
Common causes:
- Cannot read configuration
- Cannot write state files
- Cannot access log directory
# With read-only configchmod 000 ~/.config/nextdns-blocker/config.jsonnextdns-blocker config pushecho $? # Returns: 5130 - Interrupted
Section titled “130 - Interrupted”User pressed Ctrl+C during execution.
nextdns-blocker config push # Press Ctrl+Cecho $? # Returns: 130Using Exit Codes
Section titled “Using Exit Codes”In Shell Scripts
Section titled “In Shell Scripts”#!/bin/bash
nextdns-blocker config pushexit_code=$?
case $exit_code in 0) echo "Sync successful" ;; 2) echo "Configuration error - check config.json" exit 1 ;; 3) echo "API error - check credentials" exit 1 ;; *) echo "Unknown error: $exit_code" exit 1 ;;esacConditional Execution
Section titled “Conditional Execution”# Only proceed if sync succeedsnextdns-blocker config push && echo "Sync complete"
# Handle failurenextdns-blocker config push || echo "Sync failed"In CI/CD
Section titled “In CI/CD”# GitHub Actions example- name: Sync domains run: nextdns-blocker config push continue-on-error: false # Fail job on non-zero exitIn Cron
Section titled “In Cron”# Log exit code*/2 * * * * nextdns-blocker config push; echo "Exit: $?" >> /tmp/sync.logCommand-Specific Behavior
Section titled “Command-Specific Behavior”| Scenario | Exit Code |
|---|---|
| All domains synced | 0 |
| Configuration invalid | 2 |
| API connection failed | 3 |
| Partial success (some domains) | 0 |
config validate
Section titled “config validate”| Scenario | Exit Code |
|---|---|
| Configuration valid | 0 |
| JSON syntax error | 2 |
| Invalid field values | 2 |
| File not found | 2 |
unblock
Section titled “unblock”| Scenario | Exit Code |
|---|---|
| Unblock successful | 0 |
| Pending action created | 0 |
| Domain not in blocklist | 1 |
| Protected domain | 1 |
| Panic mode active | 1 |
| Scenario | Exit Code |
|---|---|
| Panic activated | 0 |
| Duration too short | 4 |
| Already in panic | 1 |
watchdog install
Section titled “watchdog install”| Scenario | Exit Code |
|---|---|
| Jobs installed | 0 |
| Permission denied | 5 |
| Already installed | 0 |
Scripting Examples
Section titled “Scripting Examples”Health Check
Section titled “Health Check”#!/bin/bashif nextdns-blocker status > /dev/null 2>&1; then echo "OK" exit 0else echo "FAIL" exit 1fiRetry on Failure
Section titled “Retry on Failure”#!/bin/bashmax_attempts=3attempt=1
while [ $attempt -le $max_attempts ]; do nextdns-blocker config push if [ $? -eq 0 ]; then exit 0 fi echo "Attempt $attempt failed, retrying..." attempt=$((attempt + 1)) sleep 10done
echo "All attempts failed"exit 1Notification on Error
Section titled “Notification on Error”#!/bin/bashnextdns-blocker config pushexit_code=$?
if [ $exit_code -ne 0 ]; then # Send notification (example with curl to webhook) curl -X POST -H "Content-Type: application/json" \ -d "{\"text\": \"NextDNS Blocker sync failed with code $exit_code\"}" \ "$NOTIFICATION_WEBHOOK"fi
exit $exit_code