Skip to content

Exit codes

Every nxstate invocation exits with a predictable numeric code. Scripts, CI pipelines, and agent loops can branch on these codes without parsing stderr text. The codes are stable across minor versions.

nxstate schema always returns the canonical, version-locked table under the exit_codes key:

Terminal window
nxstate schema | jq .exit_codes
{
"ok": 0,
"generic_error": 1,
"usage": 2,
"empty_results": 3,
"auth_required": 4,
"not_found": 5,
"permission": 6,
"rate_limited": 7,
"retryable": 8,
"unreachable": 9,
"config_error": 10,
"write_refused": 11,
"input_required": 13,
"parse_unavailable": 14,
"partial": 15,
"cancelled": 130
}

The table below is the human-readable companion to that output.

CodeMachine nameWhen it occurs
0okCommand completed successfully.
1generic_errorAn unexpected error occurred that does not fit a more specific code.
2usageBad CLI invocation — unknown flag, missing required argument, or no target host given (HOST_REQUIRED).
3empty_resultsThe device responded successfully but returned no rows or an empty data set.
4auth_requiredAuthentication failed — wrong password, key rejected, or no credentials found (AUTH_REQUIRED).
5not_foundThe requested resource (interface, VRF, device name, etc.) does not exist on the device (NOT_FOUND).
6permissionThe operation is gated and the required flag was not passed. Covers DEBUG_BLOCKED (use --allow-debug) and TECH_BLOCKED (use --allow-tech). Also raised when the NX-OS user account lacks privilege to run the command.
7rate_limitedThe device or NX-API endpoint rejected the request due to rate limiting. Back off and retry.
8retryableA transient failure occurred (timeout, partial read). Retrying the same command is likely to succeed.
9unreachableThe device could not be reached — TCP refused, SSH handshake failed, DNS not resolving (UNREACHABLE). Also the exit code from nxstate doctor when any check fails.
10config_errorA configuration problem prevented execution — for example, the OS keyring is unavailable (KEYRING_UNAVAILABLE), the inventory file is malformed, or an option combination is invalid.
11write_refusedThe show or debug passthrough rejected a non-read command (WRITE_REFUSED). nxstate validates the command before connecting to the device: anything that does not start with show, or whose first token matches a forbidden leader (conf, configure, write, wr, copy, reload, clear, no, set, delete, erase, format, reset, shutdown, and others), is refused immediately. There is no override flag — nxstate is read-only by design.
13input_requiredAn interactive prompt was needed but --no-input is set, or the process has no TTY. Pass the missing value via a flag, environment variable, or --password-stdin (INPUT_REQUIRED).
14parse_unavailableThe response could not be parsed and no fallback parser (Genie, ntc-templates) was available. Install the [genie] extra or check for a supported NTCTemplates entry.
15partialFan-out across multiple devices completed, but at least one device failed. NDJSON output is still written to stdout for the devices that succeeded; per-device errors are embedded in the stream.
130cancelledThe process received an interrupt signal (Ctrl-C / SIGINT).

When an error occurs, nxstate writes to stderr (stdout carries only data). The format depends on --format:

Plain (default)

error: refused non-read command: 'conf t' (only 'show ...' read commands are permitted)
code: WRITE_REFUSED
fix: nxstate is read-only; only 'show ...' commands are permitted (no conf t / mutations)

JSON (--format json or --json)

{
"error": "refused non-read command: 'conf t' (only 'show ...' read commands are permitted)",
"code": "WRITE_REFUSED",
"remediation": "nxstate is read-only; only 'show ...' commands are permitted (no conf t / mutations)"
}

The code field is the machine name (all-caps snake-case) and is stable. Parse code, not the human-readable error string.

Terminal window
nxstate interface list
# exit 2 (usage / HOST_REQUIRED)

Pass --host, set NXSTATE_HOST, or use --device / --group with an inventory file. See inventory and fan-out.

Terminal window
nxstate system version --host sw01 --username baduser
# exit 4 (auth_required / AUTH_REQUIRED)

Run nxstate auth login --host sw01 --username <user> to store the credential in the OS keyring, or export NXSTATE_PASSWORD. See authentication.

Terminal window
nxstate doctor --host 10.0.0.99 --username admin
# exit 9 (unreachable / UNREACHABLE)

Check connectivity, firewall rules, and whether NX-API or SSH is enabled on the device. See troubleshooting.

Terminal window
nxstate show "conf t"
# exit 11 (write_refused / WRITE_REFUSED) — NO connection is made

nxstate validates the command locally. conf, configure, write, clear, reload, no, and similar leaders are refused without opening a session to the device. See read-only safety.

Terminal window
nxstate debug "ip packet eth1/1"
# exit 6 (permission / DEBUG_BLOCKED)

Re-run with --allow-debug after verifying you understand the control-plane impact. nxstate tech-support similarly requires --allow-tech (also exit 6 / TECH_BLOCKED when omitted).

Terminal window
nxstate interface list --group core
# exit 15 (partial) if ≥1 device failed

Inspect the NDJSON stream. Each object has "ok": true|false; failed objects include an error field with code, message, and remediation. Successful devices’ data is still present.

Terminal window
nxstate system version --host sw01 --username admin --no-input
# exit 13 (input_required / INPUT_REQUIRED) when no credential is found

Supply the password via NXSTATE_PASSWORD or --password-stdin when running non-interactively.

Terminal window
nxstate interface list --host sw01 --format json > ifaces.json
code=$?
case $code in
0) echo "ok" ;;
3) echo "no interfaces returned" ;;
4) echo "auth failed — check credentials" ;;
9) echo "device unreachable" ;;
11) echo "BUG: tried to run a write command" ;;
15) echo "partial: some devices failed, check NDJSON" ;;
*) echo "unexpected error: $code" ;;
esac