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