@@ -10,13 +10,14 @@ use num_enum::TryFromPrimitiveError;
1010use std:: error:: Error ;
1111use std:: fmt:: { Display , Formatter } ;
1212
13- #[ derive( Debug , PartialEq , Clone , Copy , Eq ) ]
13+ #[ derive( Debug , PartialEq , Clone , Eq ) ]
1414pub enum ParserBmpError {
1515 InvalidOpenBmpHeader ,
1616 UnsupportedOpenBmpMessage ,
1717 UnknownTlvType ,
1818 UnknownTlvValue ,
1919 CorruptedBmpMessage ,
20+ CorruptedBgpMessage ( String ) ,
2021 TruncatedBmpMessage ,
2122}
2223
@@ -41,6 +42,9 @@ impl Display for ParserBmpError {
4142 ParserBmpError :: UnknownTlvValue => {
4243 write ! ( f, "Unknown TLV value" )
4344 }
45+ ParserBmpError :: CorruptedBgpMessage ( s) => {
46+ write ! ( f, "Corrupted BGP message: {}" , s)
47+ }
4448 }
4549 }
4650}
@@ -55,8 +59,8 @@ impl From<std::io::Error> for ParserBmpError {
5559}
5660
5761impl From < ParserError > for ParserBmpError {
58- fn from ( _ : ParserError ) -> Self {
59- ParserBmpError :: CorruptedBmpMessage
62+ fn from ( e : ParserError ) -> Self {
63+ ParserBmpError :: CorruptedBgpMessage ( e . to_string ( ) )
6064 }
6165}
6266
@@ -126,6 +130,10 @@ mod tests {
126130 ParserBmpError :: CorruptedBmpMessage . to_string( ) ,
127131 "Corrupted BMP message"
128132 ) ;
133+ assert_eq ! (
134+ ParserBmpError :: CorruptedBgpMessage ( "test" . to_string( ) ) . to_string( ) ,
135+ "Corrupted BGP message: test"
136+ ) ;
129137 assert_eq ! (
130138 ParserBmpError :: TruncatedBmpMessage . to_string( ) ,
131139 "Truncated BMP message"
@@ -148,7 +156,7 @@ mod tests {
148156 ) ;
149157 assert_eq ! (
150158 ParserBmpError :: from( ParserError :: ParseError ( "test" . to_string( ) ) ) ,
151- ParserBmpError :: CorruptedBmpMessage
159+ ParserBmpError :: CorruptedBgpMessage ( "Error: test" . to_string ( ) )
152160 ) ;
153161 assert_eq ! (
154162 ParserBmpError :: from( TryFromPrimitiveError :: <BmpMsgType >:: new( 0 ) ) ,
0 commit comments