systemprompt_identifiers/
error.rs1use thiserror::Error;
18
19#[derive(Debug, Clone, Error)]
20pub enum IdValidationError {
21 #[error("{id_type} cannot be empty")]
22 Empty { id_type: &'static str },
23 #[error("{id_type}: {message}")]
24 Invalid {
25 id_type: &'static str,
26 message: String,
27 },
28}
29
30impl IdValidationError {
31 #[must_use]
32 pub const fn empty(id_type: &'static str) -> Self {
33 Self::Empty { id_type }
34 }
35
36 #[must_use]
37 pub fn invalid(id_type: &'static str, message: impl Into<String>) -> Self {
38 Self::Invalid {
39 id_type,
40 message: message.into(),
41 }
42 }
43}
44
45#[derive(Debug, Clone, Error)]
46pub enum DbValueError {
47 #[error("cannot convert NULL to {target}")]
48 Null { target: &'static str },
49 #[error("cannot convert {from} to {target}")]
50 Incompatible {
51 from: &'static str,
52 target: &'static str,
53 },
54 #[error("cannot parse {value:?} as {target}")]
55 Parse { value: String, target: &'static str },
56 #[error("value out of range for {target}")]
57 OutOfRange { target: &'static str },
58}
59
60impl DbValueError {
61 #[must_use]
62 pub const fn null_for(target: &'static str) -> Self {
63 Self::Null { target }
64 }
65
66 #[must_use]
67 pub const fn incompatible(from: &'static str, target: &'static str) -> Self {
68 Self::Incompatible { from, target }
69 }
70
71 #[must_use]
72 pub fn parse(value: impl Into<String>, target: &'static str) -> Self {
73 Self::Parse {
74 value: value.into(),
75 target,
76 }
77 }
78
79 #[must_use]
80 pub const fn out_of_range(target: &'static str) -> Self {
81 Self::OutOfRange { target }
82 }
83}