use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
#[schemars(rename = "cli.Error")]
pub struct Error {
pub r#type: ErrorType,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub level: Option<Level>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[schemars(extend("omitempty" = true))]
pub fatal: Option<bool>,
pub message: serde_json::Value,
}
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
Copy,
PartialEq,
Eq,
JsonSchema,
)]
#[serde(rename_all = "snake_case")]
#[schemars(rename = "cli.ErrorType")]
pub enum ErrorType {
Error,
}
#[derive(
Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema,
)]
#[serde(rename_all = "lowercase")]
#[schemars(rename = "cli.Level")]
pub enum Level {
Trace,
Debug,
Info,
Warn,
Error,
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for Error {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.message {
serde_json::Value::String(s) => f.write_str(s),
other => write!(f, "{other}"),
}
}
}
impl std::error::Error for Error {}