use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ErrorCode {
InvalidJson,
NotInitialized,
VersionMismatch,
InvalidRequest,
Unsupported,
SessionNotFound,
TurnActive,
TurnNotFound,
ApprovalNotFound,
QueueLimit,
QueueNotFound,
QueueConflict,
ComponentError,
DelegationError,
RestartError,
ConfirmError,
ProviderError,
ContextLimit,
StepLimit,
HistoryLimit,
ResponseLimit,
ToolLimit,
InternalError,
#[serde(other)]
Unknown,
}
impl ErrorCode {
pub fn as_str(self) -> &'static str {
match self {
Self::InvalidJson => "invalid_json",
Self::NotInitialized => "not_initialized",
Self::VersionMismatch => "version_mismatch",
Self::InvalidRequest => "invalid_request",
Self::Unsupported => "unsupported",
Self::SessionNotFound => "session_not_found",
Self::TurnActive => "turn_active",
Self::TurnNotFound => "turn_not_found",
Self::ApprovalNotFound => "approval_not_found",
Self::QueueLimit => "queue_limit",
Self::QueueNotFound => "queue_not_found",
Self::QueueConflict => "queue_conflict",
Self::ComponentError => "component_error",
Self::DelegationError => "delegation_error",
Self::RestartError => "restart_error",
Self::ConfirmError => "confirm_error",
Self::ProviderError => "provider_error",
Self::ContextLimit => "context_limit",
Self::StepLimit => "step_limit",
Self::HistoryLimit => "history_limit",
Self::ResponseLimit => "response_limit",
Self::ToolLimit => "tool_limit",
Self::InternalError => "internal_error",
Self::Unknown => "unknown",
}
}
}
impl fmt::Display for ErrorCode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ToolErrorKind {
Denied,
Cancelled,
InvalidArguments,
Unavailable,
Limit,
Failed,
UnknownTool,
#[serde(other)]
Unknown,
}
impl ToolErrorKind {
pub(crate) fn as_str(self) -> &'static str {
match self {
Self::Denied => "denied",
Self::Cancelled => "cancelled",
Self::InvalidArguments => "invalid_arguments",
Self::Unavailable => "unavailable",
Self::Limit => "limit",
Self::Failed => "failed",
Self::UnknownTool => "unknown_tool",
Self::Unknown => "unknown",
}
}
}
impl fmt::Display for ToolErrorKind {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}