@@ -8,6 +8,7 @@ use pprof::{ProfilerGuard, ProfilerGuardBuilder, Report};
88
99use crate :: backends:: Backend ;
1010use crate :: backends:: State ;
11+ use crate :: PyroscopeError ;
1112use crate :: Result ;
1213
1314#[ derive( Default ) ]
@@ -31,10 +32,7 @@ impl Backend for Pprof<'_> {
3132 fn initialize ( & mut self , sample_rate : i32 ) -> Result < ( ) > {
3233 // Check if Backend is Uninitialized
3334 if self . state != State :: Uninitialized {
34- //return Err(crate::error::PyroscopeError {
35- //msg: String::from("Pprof Backend is already Initialized"),
36- //});
37- return Err ( crate :: error:: PyroscopeError :: default ( ) ) ;
35+ return Err ( PyroscopeError :: new ( "Pprof Backend is already Initialized" ) ) ;
3836 }
3937
4038 // Construct a ProfilerGuardBuilder
@@ -51,10 +49,7 @@ impl Backend for Pprof<'_> {
5149 fn start ( & mut self ) -> Result < ( ) > {
5250 // Check if Backend is Ready
5351 if self . state != State :: Ready {
54- //return Err(crate::error::PyroscopeError {
55- //msg: String::from("Pprof Backend is not Ready"),
56- //});
57- return Err ( crate :: error:: PyroscopeError :: default ( ) ) ;
52+ return Err ( PyroscopeError :: new ( "Pprof Backend is not Ready" ) ) ;
5853 }
5954
6055 self . guard = Some ( self . inner_builder . as_ref ( ) . unwrap ( ) . clone ( ) . build ( ) ?) ;
@@ -68,11 +63,7 @@ impl Backend for Pprof<'_> {
6863 fn stop ( & mut self ) -> Result < ( ) > {
6964 // Check if Backend is Running
7065 if self . state != State :: Running {
71- //return Err(crate::error::PyroscopeError {
72- //msg: String::from("Pprof Backend is not Running"),
73- //});
74-
75- return Err ( crate :: error:: PyroscopeError :: default ( ) ) ;
66+ return Err ( PyroscopeError :: new ( "Pprof Backend is not Running" ) ) ;
7667 }
7768
7869 // drop the guard
@@ -87,10 +78,7 @@ impl Backend for Pprof<'_> {
8778 fn report ( & mut self ) -> Result < Vec < u8 > > {
8879 // Check if Backend is Running
8980 if self . state != State :: Running {
90- //return Err(crate::error::PyroscopeError {
91- //msg: String::from("Pprof Backend is not Running"),
92- //});
93- return Err ( crate :: error:: PyroscopeError :: default ( ) ) ;
81+ return Err ( PyroscopeError :: new ( "Pprof Backend is not Running" ) ) ;
9482 }
9583
9684 let mut buffer = Vec :: new ( ) ;
@@ -107,7 +95,9 @@ impl Backend for Pprof<'_> {
10795
10896// Copyright: https://github.com/YangKeao
10997fn fold < W > ( report : & Report , with_thread_name : bool , mut writer : W ) -> Result < ( ) >
110- where W : std:: io:: Write {
98+ where
99+ W : std:: io:: Write ,
100+ {
111101 for ( key, value) in report. data . iter ( ) {
112102 if with_thread_name {
113103 if !key. thread_name . is_empty ( ) {
0 commit comments