monoloop_connector_codex/
error.rs1use monoloop_contracts::{ConnectorError, ConnectorErrorKind};
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct CodexConnectorError {
8 pub kind: ConnectorErrorKind,
10 pub message: String,
12}
13
14impl CodexConnectorError {
15 pub fn configuration(msg: impl Into<String>) -> Self {
17 Self {
18 kind: ConnectorErrorKind::ConfigurationInvalid,
19 message: msg.into(),
20 }
21 }
22
23 pub fn connection(msg: impl Into<String>) -> Self {
25 Self {
26 kind: ConnectorErrorKind::ConnectionFailed,
27 message: msg.into(),
28 }
29 }
30
31 pub fn protocol(msg: impl Into<String>) -> Self {
33 Self {
34 kind: ConnectorErrorKind::ProtocolFailed,
35 message: msg.into(),
36 }
37 }
38
39 pub fn deadline(msg: impl Into<String>) -> Self {
41 Self {
42 kind: ConnectorErrorKind::DeadlineExceeded,
43 message: msg.into(),
44 }
45 }
46
47 pub fn session(msg: impl Into<String>) -> Self {
49 Self {
50 kind: ConnectorErrorKind::SessionFailed,
51 message: msg.into(),
52 }
53 }
54
55 pub fn cancelled() -> Self {
57 Self {
58 kind: ConnectorErrorKind::Cancelled,
59 message: "codex session cancelled".into(),
60 }
61 }
62
63 pub fn into_connector_error(self) -> ConnectorError {
65 ConnectorError::new(self.kind, self.message)
66 }
67}
68
69impl From<CodexConnectorError> for ConnectorError {
70 fn from(e: CodexConnectorError) -> Self {
71 e.into_connector_error()
72 }
73}
74
75impl std::fmt::Display for CodexConnectorError {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 write!(f, "{:?}: {}", self.kind, self.message)
78 }
79}
80
81impl std::error::Error for CodexConnectorError {}