1use crate::parse_error::OMLCodeReason;
2use crate::{ConfReason, config_error::ConfCore};
3use derive_more::From;
4
5use orion_error::{OrionError, StructError, UnifiedReason};
6use orion_sec::OrionSecReason;
7use serde::Serialize;
8use thiserror::Error;
9
10pub type RunError = StructError<RunReason>;
11pub type RunResult<T> = Result<T, RunError>;
12
13#[derive(Debug, Error, PartialEq, Serialize, From)]
14pub enum DistFocus {
15 #[error("sink error : {0}")]
16 SinkError(String),
17 #[error("stg-ctrl")]
18 StgCtrl,
19}
20#[derive(Debug, Error, PartialEq, Serialize)]
21pub enum SourceFocus {
22 #[error("no data")]
23 NoData,
24 #[error("eof")]
25 Eof,
26 #[error("supplier error : {0}")]
27 SupplierError(String),
28 #[error("other : {0}")]
29 Other(String),
30 #[from(skip)]
31 #[error("disconnect : {0}")]
32 Disconnect(String),
33}
34
35#[derive(Debug, PartialEq, Serialize, From, OrionError)]
36pub enum RunReason {
37 #[orion_error(identity = "biz.dist")]
38 Dist(DistFocus),
39 #[orion_error(identity = "biz.source")]
40 Source(SourceFocus),
41 #[orion_error(transparent)]
42 Uvs(UnifiedReason),
43}
44
45impl From<ConfReason<ConfCore>> for RunReason {
46 fn from(_: ConfReason<ConfCore>) -> Self {
47 Self::core_conf()
48 }
49}
50impl From<OMLCodeReason> for RunReason {
51 fn from(_: OMLCodeReason) -> Self {
52 Self::core_conf()
53 }
54}
55
56impl From<OrionSecReason> for RunReason {
57 fn from(value: OrionSecReason) -> Self {
58 match value {
59 OrionSecReason::Sec(_) => Self::core_conf(),
60 OrionSecReason::General(uvs_reason) => Self::Uvs(uvs_reason),
61 }
62 }
63}
64
65pub trait RunErrorOwe<T> {
66 fn owe_sink(self) -> RunResult<T>;
67 fn owe_source(self) -> RunResult<T>;
68}
69
70impl<T, E> RunErrorOwe<T> for Result<T, E>
71where
72 E: std::fmt::Display,
73{
74 fn owe_sink(self) -> RunResult<T> {
75 match self {
76 Ok(v) => Ok(v),
77 Err(e) => Err(RunReason::Dist(DistFocus::SinkError("sink fail".into()))
78 .to_err()
79 .with_detail(e.to_string())),
80 }
81 }
82 fn owe_source(self) -> RunResult<T> {
83 match self {
84 Ok(v) => Ok(v),
85 Err(e) => Err(
86 RunReason::Source(SourceFocus::SupplierError("source fail".into()))
87 .to_err()
88 .with_detail(e.to_string()),
89 ),
90 }
91 }
92}
93
94impl From<SourceReason> for RunReason {
108 fn from(e: SourceReason) -> Self {
109 match e {
110 SourceReason::NotData => Self::Source(SourceFocus::NoData),
111 SourceReason::EOF => Self::Source(SourceFocus::Eof),
112 SourceReason::SupplierError => Self::Source(SourceFocus::SupplierError(String::new())),
113 SourceReason::Disconnect => Self::Source(SourceFocus::Disconnect(String::new())),
114 SourceReason::Other => Self::Source(SourceFocus::Other(String::new())),
115 SourceReason::Uvs(uvs) => Self::Uvs(uvs),
116 }
117 }
119}
120
121impl From<SinkReason> for RunReason {
122 fn from(e: SinkReason) -> Self {
123 match e {
124 SinkReason::Sink => Self::Dist(DistFocus::SinkError(String::new())),
125 SinkReason::Mock => Self::Dist(DistFocus::StgCtrl),
127 SinkReason::StgCtrl => Self::Dist(DistFocus::StgCtrl),
128 SinkReason::Uvs(uvs) => Self::Uvs(uvs),
129 }
130 }
131}
132use orion_conf::ToStructError as _;
133use orion_conf::error::ConfIOReason;
134use wp_connector_api::{SinkReason, SourceReason};
135impl From<ConfIOReason> for RunReason {
136 fn from(value: ConfIOReason) -> Self {
137 match value {
138 ConfIOReason::Other(_) => RunReason::core_conf(),
139 ConfIOReason::General(uvs) => RunReason::Uvs(uvs),
140 ConfIOReason::NoFormatEnabled => RunReason::core_conf(),
141 }
142 }
143}