gesha_core/conversions/
error.rs1use gesha_collections::partial_result::PartialResult;
2use gesha_collections::tracking::{ContextAppendable, ContextBindable};
3use std::fmt::Debug;
4
5pub type Result<A> = std::result::Result<A, Error>;
6
7pub type Output<A> = PartialResult<A, Error>;
8
9#[derive(Debug)]
10pub enum Error {
11 EnumFormatMismatch {
14 format: String,
15 value: String,
16 },
17
18 Enclosed {
19 key: String,
20 cause: Box<Error>,
21 },
22
23 FormatFailed {
29 detail: String,
30 },
31
32 InvalidToken {
35 target: String,
36 },
37
38 Multiple(Vec<Error>),
39
40 ReferenceObjectNotFound(String),
43
44 TransformBroken {
47 detail: String,
48 },
49
50 Unimplemented {
54 message: String,
55 },
56}
57
58impl ContextBindable<String> for Error {
59 fn bind(key: impl Into<String>, causes: Vec<Self>) -> Self {
60 Self::Enclosed {
61 key: key.into(),
62 cause: Box::new(causes.into()),
63 }
64 }
65}
66
67impl ContextAppendable<String> for Error {
68 fn append(key: impl Into<String>, cause: Self) -> Self {
69 Self::Enclosed {
70 key: key.into(),
71 cause: Box::new(cause),
72 }
73 }
74}
75
76impl From<Vec<Error>> for Error {
77 fn from(mut causes: Vec<Error>) -> Self {
78 if causes.len() == 1 {
79 causes.remove(0)
80 } else {
81 Error::Multiple(causes)
82 }
83 }
84}
85
86#[macro_export]
87macro_rules! broken {
88 ($shape: expr) => {
89 $crate::conversions::Error::TransformBroken {
90 detail: format!(
91 "unprocessed shape found:\n at {file}:{line}\n{shape:#?}",
92 file = file!(),
93 line = line!(),
94 shape = $shape,
95 ),
96 }
97 };
98}
99
100#[macro_export]
101macro_rules! broken_defs {
102 ($name: expr) => {
103 $crate::conversions::Error::TransformBroken {
104 detail: format!(
105 "unprocessed defs found: {name}\n at {file}:{line}",
106 name = $name,
107 file = file!(),
108 line = line!(),
109 ),
110 }
111 };
112}