wp_parse_api/
error.rs

1use serde::Serialize;
2use thiserror::Error;
3
4#[derive(Error, Debug, PartialEq)]
5pub enum DataErrKind {
6    #[error("format error : {0}\n{1:?} ")]
7    FormatError(String, Option<String>),
8    #[error("not complete")]
9    NotComplete,
10    #[error("no parse data: {0}")]
11    UnParse(String),
12
13    #[error("less data")]
14    LessData,
15    #[error("empty data")]
16    EmptyData,
17    #[error("struct less : {0}")]
18    LessStc(String),
19    #[error("define less : {0}")]
20    LessDef(String),
21}
22
23impl From<String> for DataErrKind {
24    fn from(value: String) -> Self {
25        DataErrKind::FormatError(value, None)
26    }
27}
28
29use derive_more::From;
30use orion_error::ErrorCode;
31use orion_error::StructError;
32use orion_error::ToStructError;
33use orion_error::UvsDataFrom;
34use orion_error::UvsReason;
35
36#[derive(Error, Debug, Clone, PartialEq, Serialize, From)]
37pub enum WparseReason {
38    #[from(skip)]
39    #[error("plugin >{0}")]
40    Plugin(String),
41    #[error("not match")]
42    NotMatch,
43    #[error("line proc > {0}")]
44    LineProc(String),
45    #[error("{0}")]
46    Uvs(UvsReason),
47}
48impl ErrorCode for WparseReason {
49    fn error_code(&self) -> i32 {
50        500
51    }
52}
53
54pub type WparseError = StructError<WparseReason>;
55
56//universal_owe!(ParseEngineError, ParseOweUniversal);
57
58impl From<DataErrKind> for WparseError {
59    fn from(value: DataErrKind) -> Self {
60        WparseReason::from_data(format!("{}", value), None).to_err()
61    }
62}
63pub type WparseResult<T> = Result<T, WparseError>;
64
65/// 兼容别名:保留历史命名,方便渐进迁移。
66#[deprecated(note = "use `WparseReason` instead")]
67pub type WplParseReason = WparseReason;
68
69#[deprecated(note = "use `WparseError` instead")]
70pub type WplParseError = WparseError;
71
72#[deprecated(note = "use `WparseResult` instead")]
73pub type WplParseResult<T> = WparseResult<T>;