fallow_output/error_envelope.rs
1//! The structured error envelope emitted on stdout for `--format json`.
2
3use serde::Serialize;
4
5/// Structured JSON error emitted on stdout when `--format json` is active and a
6/// command fails. It carries no `kind` discriminator: it is distinguished from
7/// the kind-tagged success envelopes by the required `error: true` field, and is
8/// a document-root branch alongside `FallowOutput` and `CodeClimateOutput` in
9/// `docs/output-schema.json`. Agents that pass `--format json` and observe a
10/// non-zero exit code parse this shape from stdout.
11#[derive(Debug, Clone, Serialize)]
12#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
13pub struct ErrorOutput {
14 /// Always `true`. The discriminator that separates an error document from a
15 /// success envelope (which instead carries a `kind`).
16 pub error: bool,
17 /// Human-readable error message.
18 pub message: String,
19 /// The process exit code the CLI returns alongside this document.
20 pub exit_code: u8,
21}
22
23impl ErrorOutput {
24 /// Build an error envelope for the given message and exit code.
25 #[must_use]
26 pub fn new(message: impl Into<String>, exit_code: u8) -> Self {
27 Self {
28 error: true,
29 message: message.into(),
30 exit_code,
31 }
32 }
33}