@@ -6,12 +6,8 @@ pub type Result<T> = std::result::Result<T, Error>;
66
77#[ derive( Debug , thiserror:: Error ) ]
88pub enum Error {
9- #[ error( "MacParseError: {0}" ) ]
10- MacParseError ( #[ from] MacParseError ) ,
11- #[ error( "NsError: {0}" ) ]
12- NsError ( #[ from] NsError ) ,
13- #[ error( "VethError: {0}" ) ]
14- VethError ( #[ from] VethError ) ,
9+ #[ error( "RattanEnvError: {0}" ) ]
10+ RattanEnvError ( #[ from] rattan_env:: Error ) ,
1511 #[ error( "RoutingTableError: {0}" ) ]
1612 RoutingTableError ( #[ from] RoutingTableError ) ,
1713 #[ error( "Encounter IO error, {0}" ) ]
@@ -44,65 +40,6 @@ pub enum Error {
4440 Custom ( String ) ,
4541}
4642
47- #[ derive( Debug , thiserror:: Error ) ]
48- pub enum NsError {
49- #[ error( "Can not create netns directory, {0}" ) ]
50- CreateNsDirError ( std:: io:: Error ) ,
51-
52- #[ error( "Can not create netns, {0}" ) ]
53- CreateNsError ( std:: io:: Error ) ,
54-
55- #[ error( "Can not open netns {0}, {1}" ) ]
56- OpenNsError ( std:: path:: PathBuf , std:: io:: Error ) ,
57-
58- #[ error( "Failed to close netns, {0}" ) ]
59- CloseNsError ( nix:: Error ) ,
60-
61- #[ error( "Failed to mount {0}, {1}" ) ]
62- MountError ( String , nix:: Error ) ,
63-
64- #[ error( "Failed to unmount {0}, {1}" ) ]
65- UnmountError ( std:: path:: PathBuf , nix:: Error ) ,
66-
67- #[ error( "Failed to unshare, {0}" ) ]
68- UnshareError ( nix:: Error ) ,
69-
70- #[ error( "Failed to join thread, {0}" ) ]
71- JoinThreadError ( String ) ,
72-
73- #[ error( "Can not setns, {0}" ) ]
74- SetNsError ( nix:: Error ) ,
75- }
76-
77- /// An error that may occur when parsing a MAC address string.
78- #[ derive( Copy , Clone , Debug , Eq , PartialEq , Hash , thiserror:: Error ) ]
79- pub enum MacParseError {
80- /// Parsing of the MAC address contained an invalid digit.
81- #[ error( "Invalid digit" ) ]
82- InvalidDigit ,
83- /// The MAC address did not have the correct length.
84- #[ error( "Invalid length" ) ]
85- InvalidLength ,
86- }
87-
88- #[ derive( Debug , thiserror:: Error ) ]
89- pub enum VethError {
90- #[ error( "Can not create veth pair, {0}" ) ]
91- CreateVethPairError ( String ) ,
92- #[ error( "Encounter namespace error, {0}" ) ]
93- NsError ( #[ from] NsError ) ,
94- #[ error( "Encounter IO error, {0}" ) ]
95- IoError ( #[ from] std:: io:: Error ) ,
96- #[ error( "Encounter system error, {0}" ) ]
97- SystemError ( #[ from] nix:: errno:: Errno ) ,
98- #[ error( "Already in namespace {0}" ) ]
99- AlreadyInNamespace ( String ) ,
100- #[ error( "Set Veth error, {0}" ) ]
101- SetError ( String ) ,
102- #[ error( "Failed to build veth, {0}" ) ]
103- TokioRuntimeError ( #[ from] TokioRuntimeError ) ,
104- }
105-
10643#[ derive( Debug , thiserror:: Error ) ]
10744pub enum RoutingTableError {
10845 #[ error( "IpNet parse error: {0}" ) ]
@@ -167,6 +104,12 @@ impl From<csv::Error> for VisualizeTraceError {
167104 }
168105}
169106
107+ impl From < rattan_env:: NsError > for Error {
108+ fn from ( e : rattan_env:: NsError ) -> Self {
109+ Error :: RattanEnvError ( e. into ( ) )
110+ }
111+ }
112+
170113#[ cfg( feature = "http" ) ]
171114impl axum:: response:: IntoResponse for Error {
172115 fn into_response ( self ) -> axum:: response:: Response {
@@ -175,9 +118,7 @@ impl axum::response::IntoResponse for Error {
175118 use serde_json:: json;
176119
177120 let status = match self {
178- Error :: MacParseError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
179- Error :: NsError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
180- Error :: VethError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
121+ Error :: RattanEnvError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
181122 Error :: RoutingTableError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
182123 Error :: IoError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
183124 Error :: MetalError ( _) => StatusCode :: INTERNAL_SERVER_ERROR ,
@@ -204,9 +145,7 @@ impl axum::response::IntoResponse for Error {
204145impl Termination for Error {
205146 fn report ( self ) -> ExitCode {
206147 match self {
207- Error :: MacParseError ( _) => ExitCode :: from ( 78 ) ,
208- Error :: NsError ( _) => ExitCode :: from ( 71 ) ,
209- Error :: VethError ( _) => ExitCode :: from ( 71 ) ,
148+ Error :: RattanEnvError ( e) => e. report ( ) ,
210149 Error :: RoutingTableError ( _) => ExitCode :: from ( 78 ) ,
211150 Error :: IoError ( _) => ExitCode :: from ( 74 ) ,
212151 Error :: MetalError ( _) => ExitCode :: from ( 74 ) ,
0 commit comments