1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! JSON emit + exit-code helpers shared by every `topodb-cli` command.
//!
//! The contract (see the plan's Global Constraints): success is a JSON value
//! on stdout with exit 0; failure is `{"error":{"kind","message"}}` on stderr
//! with exit 2 for a rejected/bad-input condition (engine `Rejected`, scope
//! parse failure, ...) or exit 1 for an internal/storage/db-open failure.
//! clap's own usage errors (missing `--db`, unknown subcommand, ...) are left
//! to clap, whose default exit code is already 2 — callers never route those
//! through `fail`.
use Value;
/// Print `value` to stdout — compact JSON, or pretty-printed if `pretty` is
/// set — and exit 0. Never returns.
!
/// Print `{"error":{"kind": kind, "message": message}}` to stderr and exit
/// `code`. Never returns. `code` is the caller's choice: 2 for a
/// rejected/bad-input condition, 1 for an internal/storage failure.
!
/// Maps a `TopoError` to the right `(kind, exit-code)` pair and calls
/// [`fail`]: `Rejected` (bad input the caller can fix — an undeclared index,
/// an empty batch, a malformed query) is `("rejected", 2)`; every other
/// variant (`Storage`, `Encoding`, `Compacted`, `Closed`,
/// `UnsupportedFormat`, and any future `#[non_exhaustive]` addition) is
/// `("internal", 1)` — the caller can't fix those by changing their input.
!