Skip to main content

objectiveai_sdk/cli/output/
error.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// A failure or advisory written to stdout. `fatal: true` means the
5/// process is exiting with a non-zero status; `fatal: false` is a
6/// non-blocking warning (e.g. auto-update failed but the requested
7/// command still ran).
8///
9/// `message` is an arbitrary JSON value so producers can emit
10/// structured payloads (e.g. `{"code": ..., "detail": ...}`). Wrap
11/// a plain string as `Value::String(...)` (or use `.into()`) and the
12/// wire bytes stay identical to the old `String`-only shape.
13#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]
14#[schemars(rename = "cli.output.Error")]
15pub struct Error {
16    pub level: Level,
17    pub fatal: bool,
18    pub message: serde_json::Value,
19    /// Stamped at emit time by [`super::Handle`] when its `agent_id`
20    /// field is set; producers leave this `None` and let the handle
21    /// fill it. Serde-skipped when `None`.
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    #[schemars(extend("omitempty" = true))]
24    pub agent_id: Option<String>,
25}
26
27/// Severity matching the conventions used by bunyan / pino / `log` crate
28/// JSON encoders. `fatal` is encoded separately on [`Error`].
29#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
30#[serde(rename_all = "lowercase")]
31#[schemars(rename = "cli.output.Level")]
32pub enum Level {
33    Trace,
34    Debug,
35    Info,
36    Warn,
37    Error,
38}