nio_client/
error.rs

1use std::fmt::{Display, Formatter};
2
3// use std::num::ParseIntError;
4use tonic::transport::Error;
5use tonic::Status;
6
7#[derive(thiserror::Error, Debug)]
8pub enum ParseErrorKind {
9    //#[error("maxlen is {0}")]
10    //LengthLimitExceeded(i32),
11    // #[error("invalid syntax: {0}")]
12    // InvalidSyntax(String),
13    #[error("invalid syntax")]
14    InvalidSyntaxWithInner(#[from] Box<dyn std::error::Error + Send + Sync>),
15    // #[error("invalid integer")]
16    // ParseInt(ParseIntError),
17}
18
19#[derive(thiserror::Error, Debug)]
20#[error("'{value}' has invalid syntax for {item}")]
21pub struct ParseError {
22    item: String,
23    value: String,
24    source: ParseErrorKind,
25    //hint: Option<&'static str>
26}
27
28#[derive(Debug)]
29pub struct ConnectError(pub(super) Error);
30
31impl Display for ConnectError {
32    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33        write!(f, "connect to check service")
34    }
35}
36
37impl std::error::Error for ConnectError {
38    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39        Some(&self.0)
40    }
41}
42
43#[derive(Debug)]
44pub struct AddError(pub(super) Status);
45
46impl Display for AddError {
47    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
48        write!(f, "add tuples grpc call")
49    }
50}
51
52impl std::error::Error for AddError {
53    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54        Some(&self.0)
55    }
56}
57
58impl From<Status> for AddError {
59    fn from(value: Status) -> Self {
60        AddError(value)
61    }
62}
63
64#[derive(Debug)]
65pub struct ReadError(pub(super) Status);
66
67impl Display for crate::error::ReadError {
68    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
69        write!(f, "read tuples grpc call")
70    }
71}
72
73impl std::error::Error for crate::error::ReadError {
74    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
75        Some(&self.0)
76    }
77}
78
79impl From<Status> for crate::error::ReadError {
80    fn from(value: Status) -> Self {
81        crate::error::ReadError(value)
82    }
83}