CLI Exit Codes and SDK Error Codes
Every nf command uses disambiguated exit codes so CI pipelines and scripts can tell
runtime errors, usage mistakes, detected changes/drift, and incomplete deferred applies
apart without parsing stdout.
CLI exit codes
| Code | Meaning | Commands / Conditions |
|---|---|---|
0 |
Success | Command completed cleanly; no changes (nf plan --expect-no-changes), no drift (nf drift check), or valid lint report (nf lint). |
1 |
Runtime or execution error | Failed plan/apply/destroy, declined approval, failed app check or finalizer, nf lint findings or unresolved values under --require-resolved, missing or invalid pyproject.toml, missing app/stack/file. |
2 |
CLI usage error | Invalid option, incompatible flags, missing required argument, or invalid choice (UsageError / Click). |
3 |
Changes or drift detected | nf plan --expect-no-changes when changes exist; nf drift check and nf drift detect when drift is found. |
4 |
Incomplete apply (deferred changes remain) | nf apply, nf deploy, or nf follow when an otherwise successful apply leaves deferred changes remaining. Configurable via incomplete_exit_code (--incomplete-exit-code 0 treats it as converged). |
124 |
Timeout | nf follow --timeout expired before the followed run ended. |
130 |
Interrupted | Process terminated by repeated Ctrl-C (SIGINT). |
Legacy passthrough commands targeting an explicit synthesized directory (nf plan|apply|destroy --stack .nf.out/...) forward the external Terraform/OpenTofu process exit code.
Python SDK (nf.sdk) error codes
In nf.sdk, commands return structured result dataclasses (where non-error statuses such
as 3 or 4 are available on result.exit_code) and raise NfError subclasses on
failure. Every NfError exposes .code, .exit_code, .message, .details, and
.to_dict().
| Exception class | .code |
Default .exit_code |
Meaning |
|---|---|---|---|
NfError |
NF_ERROR |
1 |
Base error for all SDK failures |
UsageError |
NF_USAGE |
2 |
Invalid arguments or incompatible option combination |
ProjectError |
NF_PROJECT |
1 |
Missing or invalid pyproject.toml or [tool.nf] configuration |
NotFound |
NF_NOT_FOUND |
1 |
Named app, stack, run, or file does not exist |
Ambiguous |
NF_AMBIGUOUS |
1 |
Required selector or choice was omitted and multiple candidates exist |
InputsError |
NF_INPUTS |
1 |
Invalid, unknown, missing, or disallowed (Secret) app input |
Declined |
NF_DECLINED |
1 |
Approval prompt answered no or could not be asked |
RunFailed |
NF_RUN_FAILED |
1 |
Plan, apply, destroy, or external step failed (exc.result holds partial outcome) |