Skip to content

Commit 74d2f8d

Browse files
committed
imp(error): add source and default to PyroscopeError
1 parent 146c333 commit 74d2f8d

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/backends/pprof.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ impl Backend for Pprof<'_> {
3131
fn initialize(&mut self, sample_rate: i32) -> Result<()> {
3232
// Check if Backend is Uninitialized
3333
if self.state != State::Uninitialized {
34-
return Err(crate::error::PyroscopeError {
35-
msg: String::from("Pprof Backend is already Initialized"),
36-
});
34+
//return Err(crate::error::PyroscopeError {
35+
//msg: String::from("Pprof Backend is already Initialized"),
36+
//});
37+
return Err(crate::error::PyroscopeError::default());
3738
}
3839

3940
// Construct a ProfilerGuardBuilder
@@ -50,9 +51,10 @@ impl Backend for Pprof<'_> {
5051
fn start(&mut self) -> Result<()> {
5152
// Check if Backend is Ready
5253
if self.state != State::Ready {
53-
return Err(crate::error::PyroscopeError {
54-
msg: String::from("Pprof Backend is not Ready"),
55-
});
54+
//return Err(crate::error::PyroscopeError {
55+
//msg: String::from("Pprof Backend is not Ready"),
56+
//});
57+
return Err(crate::error::PyroscopeError::default());
5658
}
5759

5860
self.guard = Some(self.inner_builder.as_ref().unwrap().clone().build()?);
@@ -66,9 +68,11 @@ impl Backend for Pprof<'_> {
6668
fn stop(&mut self) -> Result<()> {
6769
// Check if Backend is Running
6870
if self.state != State::Running {
69-
return Err(crate::error::PyroscopeError {
70-
msg: String::from("Pprof Backend is not Running"),
71-
});
71+
//return Err(crate::error::PyroscopeError {
72+
//msg: String::from("Pprof Backend is not Running"),
73+
//});
74+
75+
return Err(crate::error::PyroscopeError::default());
7276
}
7377

7478
// drop the guard
@@ -83,9 +87,10 @@ impl Backend for Pprof<'_> {
8387
fn report(&mut self) -> Result<Vec<u8>> {
8488
// Check if Backend is Running
8589
if self.state != State::Running {
86-
return Err(crate::error::PyroscopeError {
87-
msg: String::from("Pprof Backend is not Running"),
88-
});
90+
//return Err(crate::error::PyroscopeError {
91+
//msg: String::from("Pprof Backend is not Running"),
92+
//});
93+
return Err(crate::error::PyroscopeError::default());
8994
}
9095

9196
let mut buffer = Vec::new();

src/error.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use thiserror::Error;
1111
pub type Result<T> = std::result::Result<T, PyroscopeError>;
1212

1313
/// Error type of Pyroscope
14-
#[derive(Error, Debug, PartialEq)]
14+
#[derive(Error, Debug)]
1515
pub struct PyroscopeError {
1616
pub msg: String,
17+
source: Option<Box<dyn std::error::Error + Send + Sync>>,
1718
}
1819

1920
impl fmt::Display for PyroscopeError {
@@ -22,34 +23,47 @@ impl fmt::Display for PyroscopeError {
2223
}
2324
}
2425

26+
impl Default for PyroscopeError {
27+
fn default() -> Self {
28+
PyroscopeError {
29+
msg: "".to_string(),
30+
source: None,
31+
}
32+
}
33+
}
34+
2535
impl From<reqwest::Error> for PyroscopeError {
26-
fn from(_err: reqwest::Error) -> Self {
36+
fn from(err: reqwest::Error) -> Self {
2737
PyroscopeError {
2838
msg: String::from("reqwest Error"),
39+
source: Some(Box::new(err)),
2940
}
3041
}
3142
}
3243

3344
impl From<pprof::Error> for PyroscopeError {
34-
fn from(_err: pprof::Error) -> Self {
45+
fn from(err: pprof::Error) -> Self {
3546
PyroscopeError {
3647
msg: String::from("pprof Error"),
48+
source: Some(Box::new(err)),
3749
}
3850
}
3951
}
4052

4153
impl From<std::time::SystemTimeError> for PyroscopeError {
42-
fn from(_err: std::time::SystemTimeError) -> Self {
54+
fn from(err: std::time::SystemTimeError) -> Self {
4355
PyroscopeError {
4456
msg: String::from("SystemTime Error"),
57+
source: Some(Box::new(err)),
4558
}
4659
}
4760
}
4861

4962
impl From<std::io::Error> for PyroscopeError {
50-
fn from(_err: std::io::Error) -> Self {
63+
fn from(err: std::io::Error) -> Self {
5164
PyroscopeError {
5265
msg: String::from("IO Error"),
66+
source: Some(Box::new(err)),
5367
}
5468
}
5569
}
@@ -58,6 +72,7 @@ impl<T> From<std::sync::PoisonError<T>> for PyroscopeError {
5872
fn from(_err: std::sync::PoisonError<T>) -> Self {
5973
PyroscopeError {
6074
msg: String::from("Poison/Mutex Error"),
75+
source: None,
6176
}
6277
}
6378
}
@@ -66,6 +81,7 @@ impl<T> From<std::sync::mpsc::SendError<T>> for PyroscopeError {
6681
fn from(_err: std::sync::mpsc::SendError<T>) -> Self {
6782
PyroscopeError {
6883
msg: String::from("mpsc Send Error"),
84+
source: None,
6985
}
7086
}
7187
}

0 commit comments

Comments
 (0)