11use crate :: logs:: compare:: LogCmpFields ;
2- use crate :: recovery:: tally:: ValidationError ;
32
3+ use color_eyre:: Report ;
44use regex:: Regex ;
55use reqwest:: { blocking:: Client , Method , Url } ;
66
@@ -12,24 +12,6 @@ const MALFORMED_QR_MESSAGE: &str = "malformed encryption or decryption payload";
1212
1313pub type RawLog = serde_json:: Value ;
1414
15- #[ derive( Debug , thiserror:: Error ) ]
16- pub enum Error {
17- #[ error( transparent) ]
18- RequestError ( #[ from] reqwest:: Error ) ,
19-
20- #[ error( "Unable to parse log from: '{0}'" ) ]
21- LogParseError ( String ) ,
22-
23- #[ error( "Not a vote cast transaction: {fragment_id}" ) ]
24- NotVoteCastTransaction { fragment_id : String } ,
25-
26- #[ error( transparent) ]
27- UrlParseError ( #[ from] url:: ParseError ) ,
28-
29- #[ error( transparent) ]
30- ValidationError ( #[ from] ValidationError ) ,
31- }
32-
3315pub struct SentryLogClient {
3416 client : Client ,
3517 api_url : Url ,
@@ -46,33 +28,33 @@ impl SentryLogClient {
4628 }
4729 }
4830
49- pub fn get_raw_logs ( & self ) -> Result < String , Error > {
50- self . client
31+ pub fn get_raw_logs ( & self ) -> Result < String , Report > {
32+ Ok ( self
33+ . client
5134 . request ( Method :: GET , self . api_url . clone ( ) )
5235 . bearer_auth ( & self . auth_token )
5336 . send ( ) ?
5437 . bytes ( )
55- . map ( |b| std:: str:: from_utf8 ( & b) . unwrap ( ) . to_string ( ) )
56- . map_err ( Error :: RequestError )
38+ . map ( |b| std:: str:: from_utf8 ( & b) . unwrap ( ) . to_string ( ) ) ?)
5739 }
5840
59- pub fn get_json_logs ( & self ) -> Result < Vec < RawLog > , Error > {
60- self . client
41+ pub fn get_json_logs ( & self ) -> Result < Vec < RawLog > , Report > {
42+ Ok ( self
43+ . client
6144 . request ( Method :: GET , self . api_url . clone ( ) )
6245 . bearer_auth ( & self . auth_token )
6346 . send ( ) ?
64- . json ( )
65- . map_err ( Error :: RequestError )
47+ . json ( ) ?)
6648 }
6749
68- pub fn get_json_logs_chunks ( & self , chunk : usize ) -> Result < Vec < RawLog > , Error > {
50+ pub fn get_json_logs_chunks ( & self , chunk : usize ) -> Result < Vec < RawLog > , Report > {
6951 let api_url = self . api_url . join ( & format ! ( "?&cursor=0:{}:0" , chunk) ) ?;
70- self . client
52+ Ok ( self
53+ . client
7154 . request ( Method :: GET , api_url)
7255 . bearer_auth ( & self . auth_token )
7356 . send ( ) ?
74- . json ( )
75- . map_err ( Error :: RequestError )
57+ . json ( ) ?)
7658 }
7759}
7860
@@ -286,7 +268,7 @@ impl From<SentryFragmentLog> for LogCmpFields {
286268}
287269
288270impl FromStr for SentryFragmentLog {
289- type Err = Error ;
271+ type Err = Report ;
290272
291273 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
292274 let parsed = sscanf:: scanf!(
@@ -320,7 +302,7 @@ impl FromStr for SentryFragmentLog {
320302 fragment_id,
321303 } ,
322304 )
323- . ok_or_else ( || Error :: LogParseError ( s . to_string ( ) ) )
305+ . ok_or_else ( || color_eyre :: eyre :: eyre! ( "log parse error: {s}" ) )
324306 }
325307}
326308
0 commit comments