volans_core/multiaddr/
error.rs1use std::{io, net, num, str, string};
2
3use unsigned_varint::decode;
4
5use crate::identity;
6
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 #[error("Data length is less than expected")]
11 DataLessThanLen,
12 #[error("Invalid multiaddr protocol")]
13 InvalidMultiaddr,
14 #[error("Invalid protocol string")]
15 InvalidProtocol,
16 #[error("Invalid varint: {0}")]
17 InvalidVarint(#[from] decode::Error),
18 #[error("Failed to parse: {0}")]
19 ParsingError(Box<dyn std::error::Error + Send + Sync>),
20 #[error("Unknown protocol ID: {0}")]
21 UnknownProtocolId(u32),
22 #[error("Unknown protocol: {0}")]
23 UnknownProtocol(String),
24}
25
26impl From<io::Error> for Error {
27 fn from(err: io::Error) -> Error {
28 Error::ParsingError(err.into())
29 }
30}
31
32impl From<net::AddrParseError> for Error {
33 fn from(err: net::AddrParseError) -> Error {
34 Error::ParsingError(err.into())
35 }
36}
37
38impl From<num::ParseIntError> for Error {
39 fn from(err: num::ParseIntError) -> Error {
40 Error::ParsingError(err.into())
41 }
42}
43
44impl From<string::FromUtf8Error> for Error {
45 fn from(err: string::FromUtf8Error) -> Error {
46 Error::ParsingError(err.into())
47 }
48}
49
50impl From<str::Utf8Error> for Error {
51 fn from(err: str::Utf8Error) -> Error {
52 Error::ParsingError(err.into())
53 }
54}
55
56impl From<identity::Error> for Error {
57 fn from(err: identity::Error) -> Error {
58 Error::ParsingError(err.into())
59 }
60}