Skip to content

Exit Codes

What exit codes 0–6 and 130 mean, what to do next, and how to branch on them in scripts.

Every SOW command exits with one of the codes below, and a code means the same thing in every command. A script can therefore branch on the code and leave the message for humans. Look here when you wrap SOW in a script, or when you need to know whether a nonzero exit left committed work behind.

Code Meaning Next step
0 Success, or nothing to do Read the result; a command with nothing to do can report noop: true
1 Runtime I/O, package parsing, rendering, or another unclassified error Fix the reported input or environment problem, then retry
2 Invalid command line, workspace discovery failure, or invalid configuration Check sow help COMMAND, the selection flags, and sow config check
3 Partial success Read the result to separate committed work from failed items
4 Write lock unavailable Retry later or allow a longer --timeout
5 Integrity or recovery error, or the repository or target is not ready for this operation Inspect status and check; build a dirty repository, or finish the recorded operation the error names
6 Operation rejected Fix the conflict, package reference, architecture, signing setting, or protection setting the error names
130 Interrupted by SIGINT or SIGTERM Run the recovery command for the interrupted operation

Success does not always mean ready

status exits 0 whenever it can report the state, including dirty, recovering, and error. Its ready_to_copy field summarizes that state but does not check bytes. Run check before you deliver a repository:

sow build -r demo
sow check -r demo

A dirty repository can have perfectly consistent old indexes and still fail check with 5, because the desired state has not been built. Build and check again. If the diagnostic instead reports corrupted bytes or conflicting recovery evidence, investigate that first; see Troubleshooting.

Partial success

Code 3 means some work committed and some failed, so neither “retry everything” nor “carry on” is safe without reading the result:

  • add: at least one input was accepted or reused and at least one failed. The JSON result keeps a per-input outcome. A package excluded by policy is not a failure.
  • init: some declared objects were created before a later one failed.
  • prune: an error occurred after it published the filtered index or removed at least one RPM.

Capture both the output and the code before deciding whether to continue:

#!/usr/bin/env bash
set -uo pipefail

sow add ./incoming/ -r demo -d el9 --json > add-result.json
rc=$?
case "$rc" in
  0) ;;
  3) jq '.result.items[] | select(.status == "failed")' add-result.json
     exit 3 ;;
  4) echo 'Repository is busy; retry later.' >&2
     exit 4 ;;
  *) exit "$rc" ;;
esac

sow check -r demo || exit $?
sow publish mirror

The script stops on partial success so you can inspect the failed inputs before anything is published. mirror must be a configured target for demo.

Lock waits and interruption

Write commands wait for their lock without a time limit by default (-T 0). -T 30s waits up to 30 seconds and -N tries once; either returns 4 when the lock stays busy. Combining -N with a nonzero -T is a usage error (2). Read-only commands do not accept these flags. Some of them take shared locks for a consistent snapshot, while status reports writer activity without waiting for the writer.

SOW returns 130 when it handles Ctrl-C or SIGTERM. An internal timeout, such as an upload making no progress, keeps its normal error class instead. Interruption never undoes work that already committed: inspect the state and follow Transactions and recovery to resume.

JSON errors

With --json, stdout carries the result envelope and stderr carries diagnostics. Each entry in the errors array has a class that maps to the exit code:

Code JSON class
1 runtime
2 usage, discovery, or config
3 partial
4 lock
5 integrity
6 rejected
130 interrupted

Branch on the code or class, never on message text. create and prune, the commands for simple repositories, print their underlying error (starting with plain:) to stderr, and their JSON message can carry an extra CLI category prefix. When ok is false, diagnostic and partial results are still present. See JSON output for the envelope.

Table reader