obeli_sk_concepts/
error_conversions.rs1use crate::{
2 JoinSetIdParseError,
3 prefixed_ulid::{DerivedIdParseError, ExecutionIdParseError, PrefixedUlidParseError},
4 storage::{
5 DbErrorGeneric, DbErrorRead, DbErrorReadWithTimeout, DbErrorWrite,
6 SubscribeToResponsesError, VersionParseError,
7 },
8};
9use std::{panic::Location, sync::Arc};
10use tracing_error::SpanTrace;
11
12impl From<DbErrorRead> for DbErrorWrite {
13 fn from(value: DbErrorRead) -> DbErrorWrite {
14 match value {
15 DbErrorRead::NotFound => DbErrorWrite::NotFound,
16 DbErrorRead::Generic(err) => DbErrorWrite::Generic(err),
17 }
18 }
19}
20
21impl From<PrefixedUlidParseError> for DbErrorGeneric {
22 #[track_caller]
23 fn from(err: PrefixedUlidParseError) -> Self {
24 DbErrorGeneric::Uncategorized {
25 reason: err.to_string().into(),
26 context: SpanTrace::capture(),
27 source: Some(Arc::new(err)),
28 loc: Location::caller(),
29 }
30 }
31}
32
33impl From<JoinSetIdParseError> for DbErrorGeneric {
34 #[track_caller]
35 fn from(err: JoinSetIdParseError) -> Self {
36 DbErrorGeneric::Uncategorized {
37 reason: err.to_string().into(),
38 context: SpanTrace::capture(),
39 source: Some(Arc::new(err)),
40 loc: Location::caller(),
41 }
42 }
43}
44
45impl From<ExecutionIdParseError> for DbErrorGeneric {
46 #[track_caller]
47 fn from(err: ExecutionIdParseError) -> Self {
48 DbErrorGeneric::Uncategorized {
49 reason: err.to_string().into(),
50 context: SpanTrace::capture(),
51 source: Some(Arc::new(err)),
52 loc: Location::caller(),
53 }
54 }
55}
56
57impl From<VersionParseError> for DbErrorGeneric {
58 #[track_caller]
59 fn from(err: VersionParseError) -> Self {
60 DbErrorGeneric::Uncategorized {
61 reason: err.to_string().into(),
62 context: SpanTrace::capture(),
63 source: Some(Arc::new(err)),
64 loc: Location::caller(),
65 }
66 }
67}
68
69impl From<VersionParseError> for DbErrorRead {
70 fn from(err: VersionParseError) -> Self {
71 DbErrorGeneric::from(err).into()
72 }
73}
74
75impl From<DerivedIdParseError> for DbErrorGeneric {
76 #[track_caller]
77 fn from(err: DerivedIdParseError) -> Self {
78 DbErrorGeneric::Uncategorized {
79 reason: err.to_string().into(),
80 context: SpanTrace::capture(),
81 source: Some(Arc::new(err)),
82 loc: Location::caller(),
83 }
84 }
85}
86
87impl From<DbErrorGeneric> for DbErrorReadWithTimeout {
88 fn from(value: DbErrorGeneric) -> DbErrorReadWithTimeout {
89 Self::from(DbErrorRead::from(value))
90 }
91}
92
93impl From<DbErrorGeneric> for SubscribeToResponsesError {
94 fn from(value: DbErrorGeneric) -> Self {
95 Self::from(DbErrorRead::from(value))
96 }
97}