1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::{ErrorInfo, HashClear, RgResult};
use crate::structs::ResponseMetadata;

impl ErrorInfo {
    pub fn error_info<S: Into<String>>(message: S) -> ErrorInfo {
        crate::error_info(message)
    }
    pub fn new(message: impl Into<String>) -> ErrorInfo {
        crate::error_info(message.into())
    }

    pub fn response_metadata(self) -> ResponseMetadata {
        ResponseMetadata {
            success: false,
            error_info: Some(self),
            task_local_details: vec![],
            request_id: None,
            trace_id: None,
        }
    }
    pub fn enhance(self, message: impl Into<String>) -> ErrorInfo {
        let mut e = self;
        e.message = format!("{} {} ", e.message, message.into());
        e
    }
}

impl HashClear for ErrorInfo {
    fn hash_clear(&mut self) {

    }
}

pub trait EnhanceErrorInfo<T> {
    fn add(self, message: impl Into<String>) -> RgResult<T>;
    fn mark_abort(self) -> RgResult<T>;
}

impl<T> EnhanceErrorInfo<T> for RgResult<T> {
    fn add(self, message: impl Into<String>) -> RgResult<T> {
        self.map_err(|e| e.enhance(message))
    }
    fn mark_abort(mut self) -> RgResult<T> {
        self.map_err(|mut e| {
            e.abort = true;
            e
        })
    }

}