kcode_codex_runtime_v2/
error.rs1use std::fmt::{Display, Formatter};
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum ErrorKind {
6 InvalidInput,
8 Unavailable,
10 Authentication,
12 Timeout,
14 Protocol,
16 Cancelled,
18}
19
20#[derive(Clone, Debug, Eq, PartialEq)]
22pub struct Error {
23 kind: ErrorKind,
24 message: String,
25}
26
27impl Error {
28 pub(crate) fn new(kind: ErrorKind, message: impl Into<String>) -> Self {
29 Self {
30 kind,
31 message: message.into(),
32 }
33 }
34
35 pub const fn kind(&self) -> ErrorKind {
37 self.kind
38 }
39
40 pub fn message(&self) -> &str {
42 &self.message
43 }
44}
45
46impl Display for Error {
47 fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
48 formatter.write_str(&self.message)
49 }
50}
51
52impl std::error::Error for Error {}
53
54pub type Result<T> = std::result::Result<T, Error>;