burp: error: impl Display and Error
The `burp::error::Error` struct needs to implement the `std::error::Error` trait (which requires that it also implement `std::fmt::Display`) so that it can be used in dynamic dispatch situations. Notably, the `prometheus_exporter_base::render_prometheus` function requires a closure that returns `Result<String, Box<dyn std::error::Error>>`, so in order to use the `?` (early return) operator on on the `metrics::get_metrics` function call, our error must implement that trait.master
parent
c7feaa041a
commit
dc0c987358
|
@ -1,4 +1,6 @@
|
|||
//! Client error handling
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
use serde_json;
|
||||
|
@ -40,3 +42,17 @@ impl From<serde_json::Error> for Error {
|
|||
Self::Protocol(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::Io(e) => write!(f, "I/O error: {}", e),
|
||||
Self::Tls(e) => write!(f, "TLS handshake error: {}", e),
|
||||
Self::Command(e) => write!(f, "Error from BURP server: {}", e),
|
||||
Self::Protocol(e) => write!(f, "BURP protocol error: {}", e),
|
||||
Self::UnsupportedVersion(e) => write!(f, "{}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
|
Loading…
Reference in New Issue