objectiveai_sdk/cli/
error.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
20#[schemars(rename = "cli.Error")]
21pub struct Error {
22 pub r#type: ErrorType,
23 #[serde(default, skip_serializing_if = "Option::is_none")]
24 #[schemars(extend("omitempty" = true))]
25 pub level: Option<Level>,
26 #[serde(default, skip_serializing_if = "Option::is_none")]
27 #[schemars(extend("omitempty" = true))]
28 pub fatal: Option<bool>,
29 pub message: serde_json::Value,
30}
31
32#[derive(
35 Serialize,
36 Deserialize,
37 Debug,
38 Clone,
39 Copy,
40 PartialEq,
41 Eq,
42 JsonSchema,
43)]
44#[serde(rename_all = "snake_case")]
45#[schemars(rename = "cli.ErrorType")]
46pub enum ErrorType {
47 Error,
48}
49
50#[derive(
53 Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema,
54)]
55#[serde(rename_all = "lowercase")]
56#[schemars(rename = "cli.Level")]
57pub enum Level {
58 Trace,
59 Debug,
60 Info,
61 Warn,
62 Error,
63}
64
65#[cfg(feature = "mcp")]
66impl crate::cli::command::CommandResponse for Error {
67 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
68 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
69 }
70}
71
72impl std::fmt::Display for Error {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 match &self.message {
79 serde_json::Value::String(s) => f.write_str(s),
80 other => write!(f, "{other}"),
81 }
82 }
83}
84
85impl std::error::Error for Error {}