ockam_core/routing/
error.rs1use crate::{
2 errcode::{Kind, Origin},
3 Error,
4};
5use core::fmt::{self, Debug, Display};
6
7#[derive(Clone, Copy, Debug)]
9pub enum RouteError {
10 IncompleteRoute,
12}
13
14impl From<RouteError> for Error {
15 #[track_caller]
16 fn from(err: RouteError) -> Self {
17 let kind = match err {
18 RouteError::IncompleteRoute => Kind::Misuse,
19 };
20 Error::new(Origin::Core, kind, err)
21 }
22}
23
24impl crate::compat::error::Error for RouteError {}
25impl Display for RouteError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 RouteError::IncompleteRoute => write!(f, "incomplete route"),
29 }
30 }
31}
32
33#[derive(Debug)]
35pub struct AddressParseError {
36 kind: AddressParseErrorKind,
37}
38
39#[derive(Debug, Clone, PartialEq, Eq)]
41#[non_exhaustive]
42pub enum AddressParseErrorKind {
43 InvalidType(core::num::ParseIntError),
45 MultipleSep,
47}
48
49impl AddressParseError {
50 pub fn new(kind: AddressParseErrorKind) -> Self {
52 Self { kind }
53 }
54 pub fn kind(&self) -> &AddressParseErrorKind {
56 &self.kind
57 }
58}
59
60impl Display for AddressParseError {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match &self.kind {
63 AddressParseErrorKind::InvalidType(e) => {
64 write!(f, "Failed to parse address type: '{}'", e)
65 }
66 AddressParseErrorKind::MultipleSep => {
67 write!(
68 f,
69 "Invalid address string: more than one '#' separator found"
70 )
71 }
72 }
73 }
74}
75
76impl crate::compat::error::Error for AddressParseError {}