objectiveai_sdk/cli/command/
from_args_error.rs1#[derive(Debug)]
12pub struct FromArgsError {
13 pub field: &'static str,
14 pub source: FromArgsErrorSource,
15}
16
17impl FromArgsError {
18 pub fn path_parse(field: &'static str, source: String) -> Self {
24 Self {
25 field,
26 source: FromArgsErrorSource::Plain(source),
27 }
28 }
29
30 pub fn json(
36 field: &'static str,
37 source: serde_path_to_error::Error<serde_json::Error>,
38 ) -> Self {
39 Self {
40 field,
41 source: FromArgsErrorSource::Json(source),
42 }
43 }
44}
45
46#[derive(Debug)]
47pub enum FromArgsErrorSource {
48 Json(serde_path_to_error::Error<serde_json::Error>),
49 Plain(String),
50}
51
52impl From<serde_path_to_error::Error<serde_json::Error>> for FromArgsErrorSource {
53 fn from(e: serde_path_to_error::Error<serde_json::Error>) -> Self {
54 Self::Json(e)
55 }
56}
57
58impl From<String> for FromArgsErrorSource {
59 fn from(s: String) -> Self {
60 Self::Plain(s)
61 }
62}
63
64impl std::fmt::Display for FromArgsErrorSource {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 match self {
67 Self::Json(e) => write!(f, "{e}"),
68 Self::Plain(s) => f.write_str(s),
69 }
70 }
71}
72
73impl std::fmt::Display for FromArgsError {
74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75 write!(f, "argument parse error at `{}`: {}", self.field, self.source)
76 }
77}
78
79impl std::error::Error for FromArgsError {}