ferrin_spec/error/
config.rs1use super::BoxError;
4use crate::json::JsonValue;
5
6#[derive(Debug, thiserror::Error)]
8#[error("invalid argument `{argument}`: {message}")]
9pub struct InvalidArgumentError {
10 pub argument: String,
12 pub message: String,
14 #[source]
16 pub cause: Option<BoxError>,
17}
18
19impl InvalidArgumentError {
20 #[must_use]
22 pub fn new(argument: impl Into<String>, message: impl Into<String>) -> Self {
23 Self {
24 argument: argument.into(),
25 message: message.into(),
26 cause: None,
27 }
28 }
29
30 #[must_use]
32 pub fn with_cause(mut self, cause: impl std::error::Error + Send + Sync + 'static) -> Self {
33 self.cause = Some(Box::new(cause));
34 self
35 }
36}
37
38#[derive(Debug, thiserror::Error)]
40#[error("invalid prompt: {message}")]
41pub struct InvalidPromptError {
42 pub message: String,
44 pub prompt: Option<JsonValue>,
46 #[source]
48 pub cause: Option<BoxError>,
49}
50
51impl InvalidPromptError {
52 #[must_use]
54 pub fn new(message: impl Into<String>) -> Self {
55 Self {
56 message: message.into(),
57 prompt: None,
58 cause: None,
59 }
60 }
61
62 #[must_use]
64 pub fn with_prompt(mut self, prompt: JsonValue) -> Self {
65 self.prompt = Some(prompt);
66 self
67 }
68
69 #[must_use]
71 pub fn with_cause(mut self, cause: impl std::error::Error + Send + Sync + 'static) -> Self {
72 self.cause = Some(Box::new(cause));
73 self
74 }
75}
76
77#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
79#[error("{message}")]
80pub struct LoadApiKeyError {
81 pub message: String,
83}
84
85impl LoadApiKeyError {
86 #[must_use]
88 pub fn new(message: impl Into<String>) -> Self {
89 Self {
90 message: message.into(),
91 }
92 }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
97#[error("{message}")]
98pub struct LoadSettingError {
99 pub message: String,
101}
102
103impl LoadSettingError {
104 #[must_use]
106 pub fn new(message: impl Into<String>) -> Self {
107 Self {
108 message: message.into(),
109 }
110 }
111}