• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tox-rs / tox / 7247588774

18 Dec 2023 11:45AM UTC coverage: 94.85% (-0.03%) from 94.876%
7247588774

Pull #477

github

web-flow
Merge 6a5a935cc into 5ab95a61f
Pull Request #477: Add functions for tox crate version information

0 of 10 new or added lines in 1 file covered. (0.0%)

13 existing lines in 7 files now uncovered.

16816 of 17729 relevant lines covered (94.85%)

1.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/tox_packet/src/dht/errors.rs
1
/*! Errors enum for DHT packets.
2
*/
3

4
use nom::{error::Error as NomError, Err};
5
use thiserror::Error;
6

7
use std::convert::From;
8
use std::io::Error as IoError;
9
use std::io::ErrorKind as IoErrorKind;
10

11
/// Error that can happen when calling `get_payload` of packet.
12
#[derive(Debug, PartialEq, Error)]
13
pub enum GetPayloadError {
14
    /// Error indicates that received payload of encrypted packet can't be decrypted
15
    #[error("Decrypt payload error")]
16
    Decrypt,
17
    /// Error indicates that decrypted payload of packet can't be parsed
18
    #[error("Deserialize payload error: {:?}, data: {:?}", error, payload)]
19
    Deserialize {
20
        /// Parsing error
21
        error: Err<NomError<Vec<u8>>>,
22
        /// Received payload of packet
23
        payload: Vec<u8>,
24
    },
25
}
26

27
impl GetPayloadError {
28
    pub(crate) fn decrypt() -> GetPayloadError {
2✔
29
        GetPayloadError::Decrypt
2✔
30
    }
31

32
    pub(crate) fn deserialize(e: Err<NomError<&[u8]>>, payload: Vec<u8>) -> GetPayloadError {
1✔
33
        GetPayloadError::Deserialize {
34
            error: e.to_owned(),
1✔
35
            payload,
36
        }
37
    }
38
}
39

40
/// From trait for temporary use during transition from io:Error to custom enum error of failure crate
41
impl From<GetPayloadError> for IoError {
42
    fn from(item: GetPayloadError) -> Self {
×
43
        IoError::new(
UNCOV
44
            IoErrorKind::Other,
×
45
            format!("GetPayloadError occured. error: {:?}", item),
×
46
        )
47
    }
48
}
49

50
#[cfg(test)]
51
mod tests {
52
    use std::num::NonZeroUsize;
53

54
    use super::*;
55
    use nom::{
56
        error::{Error, ErrorKind},
57
        Needed,
58
    };
59

60
    #[test]
61
    fn get_payload_error_kind() {
3✔
62
        let decrypt = GetPayloadError::Decrypt;
1✔
63
        assert_eq!(format!("{}", decrypt), "Decrypt payload error".to_owned());
1✔
64

65
        let incomplete = GetPayloadError::Deserialize {
66
            error: Err::Incomplete(Needed::Size(NonZeroUsize::new(5).unwrap())),
1✔
67
            payload: vec![1, 2, 3, 4],
2✔
68
        };
69
        assert_eq!(
×
70
            format!("{}", incomplete),
1✔
71
            "Deserialize payload error: Incomplete(Size(5)), data: [1, 2, 3, 4]".to_owned()
1✔
72
        );
73

74
        let deserialize = GetPayloadError::Deserialize {
75
            error: Err::Error(Error::new(vec![], ErrorKind::Eof)),
1✔
76
            payload: vec![1, 2, 3, 4],
2✔
77
        };
78
        assert_eq!(
×
79
            format!("{}", deserialize),
1✔
80
            "Deserialize payload error: Error(Error { input: [], code: Eof }), data: [1, 2, 3, 4]".to_owned()
1✔
81
        );
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc