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