Skip to content

Exit Codes

NextDNS Blocker uses standard exit codes to indicate success or failure, enabling scripting and automation.

CodeNameDescription
0SuccessCommand completed successfully
1General ErrorUnspecified error
2Configuration ErrorInvalid or missing configuration
3API ErrorNextDNS API communication failed
4Validation ErrorInput validation failed
5Permission ErrorInsufficient permissions
130InterruptedUser interrupted (Ctrl+C)

Command completed without errors.

Terminal window
nextdns-blocker config push
echo $? # Returns: 0

An unspecified error occurred.

Common causes:

  • Unexpected exception
  • Unknown command
  • Missing required argument
Terminal window
nextdns-blocker unknown-command
echo $? # Returns: 1

Configuration file is invalid or missing.

Common causes:

  • config.json syntax error
  • Missing required fields
  • .env file not found
  • Missing API credentials
Terminal window
# With invalid config
nextdns-blocker config push
echo $? # Returns: 2

Communication with NextDNS API failed.

Common causes:

  • Invalid API key
  • Invalid profile ID
  • Network timeout
  • Rate limit exceeded
  • NextDNS service unavailable
Terminal window
# With wrong API key
nextdns-blocker config push
echo $? # Returns: 3

Input validation failed.

Common causes:

  • Invalid domain format
  • Invalid time format
  • Unknown day name
  • Invalid duration format
Terminal window
# With invalid domain
nextdns-blocker unblock "not a domain"
echo $? # Returns: 4

Insufficient file permissions.

Common causes:

  • Cannot read configuration
  • Cannot write state files
  • Cannot access log directory
Terminal window
# With read-only config
chmod 000 ~/.config/nextdns-blocker/config.json
nextdns-blocker config push
echo $? # Returns: 5

User pressed Ctrl+C during execution.

Terminal window
nextdns-blocker config push # Press Ctrl+C
echo $? # Returns: 130
#!/bin/bash
nextdns-blocker config push
exit_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
;;
esac
Terminal window
# Only proceed if sync succeeds
nextdns-blocker config push && echo "Sync complete"
# Handle failure
nextdns-blocker config push || echo "Sync failed"
# GitHub Actions example
- name: Sync domains
run: nextdns-blocker config push
continue-on-error: false # Fail job on non-zero exit
Terminal window
# Log exit code
*/2 * * * * nextdns-blocker config push; echo "Exit: $?" >> /tmp/sync.log
ScenarioExit Code
All domains synced0
Configuration invalid2
API connection failed3
Partial success (some domains)0
ScenarioExit Code
Configuration valid0
JSON syntax error2
Invalid field values2
File not found2
ScenarioExit Code
Unblock successful0
Pending action created0
Domain not in blocklist1
Protected domain1
Panic mode active1
ScenarioExit Code
Panic activated0
Duration too short4
Already in panic1
ScenarioExit Code
Jobs installed0
Permission denied5
Already installed0
health-check.sh
#!/bin/bash
if nextdns-blocker status > /dev/null 2>&1; then
echo "OK"
exit 0
else
echo "FAIL"
exit 1
fi
sync-with-retry.sh
#!/bin/bash
max_attempts=3
attempt=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 10
done
echo "All attempts failed"
exit 1
sync-notify.sh
#!/bin/bash
nextdns-blocker config push
exit_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