sqlite_graphrag/constants/exit_codes.rs
1//! Process exit codes with a documented meaning.
2//!
3//! Split out of the former single-file `constants.rs` in v1.2.5;
4//! every item is re-exported by the parent module, so `crate::constants::X`
5//! resolves exactly as before.
6
7/// Exit code for partial batch failure (PRD line 1822). Conflicts with DbBusy in v1.x;
8/// in v2.0.0 DbBusy migrates to 15 and this code takes 13 per PRD.
9pub const BATCH_PARTIAL_FAILURE_EXIT_CODE: i32 = 13;
10
11/// Exit code for DbBusy in v2.0.0 (migrated from 13 to free 13 for batch failure).
12pub const DB_BUSY_EXIT_CODE: i32 = 15;
13
14/// Process exit code returned when the lock is busy and no wait was requested (EX_TEMPFAIL).
15pub const CLI_LOCK_EXIT_CODE: i32 = 75;
16
17/// Process exit code returned when stdout is a closed pipe.
18///
19/// `141` is `128 + SIGPIPE(13)`, the Unix convention a shell reports when a
20/// consumer such as `head` or `jaq` exits early. Windows has no SIGPIPE, so the
21/// same number is produced there by classifying the stdout write error as
22/// [`std::io::ErrorKind::BrokenPipe`] — the exit-code contract is identical on
23/// Linux, macOS and Windows.
24pub const BROKEN_PIPE_EXIT_CODE: u8 = 141;
25
26/// Process exit code returned when available memory is below [`crate::constants::MIN_AVAILABLE_MEMORY_MB`].
27///
28/// Value `77` is `EX_NOPERM` in glibc sysexits, reused here to indicate
29/// "insufficient system resource to proceed".
30pub const LOW_MEMORY_EXIT_CODE: i32 = 77;
31
32/// Process exit code returned when a duplicate memory or entity is detected (exit 9).
33///
34/// Moved from `2` to `9` in v1.0.52 to free exit code `2` for future use and align
35/// with the PRD exit code contract. Shell callers and LLM agents must use `9` from
36/// this version onwards.
37pub const DUPLICATE_EXIT_CODE: i32 = 9;
38
39/// Process exit code returned when the argv is a valid parse but an invalid
40/// combination (`EX_USAGE` in spirit, `2` by this project's contract).
41///
42/// GAP-SG-201 / GAP-SG-202 / GAP-SG-203 / GAP-SG-204: the agent-native surface
43/// can only discover some usage errors once it sees the envelope — a `--filter`
44/// key that exists nowhere in the result elements, or a predicate evaluated over
45/// a page the query already truncated. Refusing those needs an error that maps
46/// to the code clap already returns for a bad command line, so an agent branches
47/// on one number for "you asked for something impossible" regardless of whether
48/// the parser or the surface caught it.
49///
50/// `2` rather than `EX_USAGE` (64): [`DUPLICATE_EXIT_CODE`] above was moved off
51/// `2` in v1.0.52 precisely to free it, `src/main.rs` already returns it for a
52/// rejected flag, and introducing 64 now would give this binary two codes for
53/// one meaning — which the exit-code rules forbid.
54pub const USAGE_EXIT_CODE: i32 = 2;
55
56/// Process exit code returned when shutdown is requested via SIGINT/SIGTERM/SIGHUP
57/// (v1.0.82, GAP-002 final).
58///
59/// The shell sees this code INSTEAD of the legacy `128 + signal` (130/143/129) so
60/// that LLM agents and orchestrators can branch on a single deterministic value
61/// when the operation was cancelled by the user. The signal name is preserved in
62/// the JSON envelope emitted before exit (`{"code":19,"signal":"SIGINT",...}`).
63pub const SHUTDOWN_EXIT_CODE: i32 = 19;