@@ -44,7 +44,6 @@ use percent_encoding::{percent_encode, utf8_percent_encode, NON_ALPHANUMERIC};
44
44
use reqwest:: header:: HeaderName ;
45
45
use reqwest:: { Client , Method , RequestBuilder , Response , StatusCode } ;
46
46
use serde:: { Deserialize , Serialize } ;
47
- use snafu:: { OptionExt , ResultExt , Snafu } ;
48
47
use std:: sync:: Arc ;
49
48
50
49
const VERSION_HEADER : & str = "x-goog-generation" ;
@@ -53,59 +52,59 @@ const USER_DEFINED_METADATA_HEADER_PREFIX: &str = "x-goog-meta-";
53
52
54
53
static VERSION_MATCH : HeaderName = HeaderName :: from_static ( "x-goog-if-generation-match" ) ;
55
54
56
- #[ derive( Debug , Snafu ) ]
55
+ #[ derive( Debug , thiserror :: Error ) ]
57
56
enum Error {
58
- #[ snafu ( display ( "Error performing list request: {}" , source) ) ]
57
+ #[ error ( "Error performing list request: {}" , source) ]
59
58
ListRequest { source : crate :: client:: retry:: Error } ,
60
59
61
- #[ snafu ( display ( "Error getting list response body: {}" , source) ) ]
60
+ #[ error ( "Error getting list response body: {}" , source) ]
62
61
ListResponseBody { source : reqwest:: Error } ,
63
62
64
- #[ snafu ( display ( "Got invalid list response: {}" , source) ) ]
63
+ #[ error ( "Got invalid list response: {}" , source) ]
65
64
InvalidListResponse { source : quick_xml:: de:: DeError } ,
66
65
67
- #[ snafu ( display ( "Error performing get request {}: {}" , path, source) ) ]
66
+ #[ error ( "Error performing get request {}: {}" , path, source) ]
68
67
GetRequest {
69
68
source : crate :: client:: retry:: Error ,
70
69
path : String ,
71
70
} ,
72
71
73
- #[ snafu ( display ( "Error performing request {}: {}" , path, source) ) ]
72
+ #[ error ( "Error performing request {}: {}" , path, source) ]
74
73
Request {
75
74
source : crate :: client:: retry:: Error ,
76
75
path : String ,
77
76
} ,
78
77
79
- #[ snafu ( display ( "Error getting put response body: {}" , source) ) ]
78
+ #[ error ( "Error getting put response body: {}" , source) ]
80
79
PutResponseBody { source : reqwest:: Error } ,
81
80
82
- #[ snafu ( display ( "Got invalid put response: {}" , source) ) ]
81
+ #[ error ( "Got invalid put response: {}" , source) ]
83
82
InvalidPutResponse { source : quick_xml:: de:: DeError } ,
84
83
85
- #[ snafu ( display ( "Unable to extract metadata from headers: {}" , source) ) ]
84
+ #[ error ( "Unable to extract metadata from headers: {}" , source) ]
86
85
Metadata {
87
86
source : crate :: client:: header:: Error ,
88
87
} ,
89
88
90
- #[ snafu ( display ( "Version required for conditional update" ) ) ]
89
+ #[ error ( "Version required for conditional update" ) ]
91
90
MissingVersion ,
92
91
93
- #[ snafu ( display ( "Error performing complete multipart request: {}" , source) ) ]
92
+ #[ error ( "Error performing complete multipart request: {}" , source) ]
94
93
CompleteMultipartRequest { source : crate :: client:: retry:: Error } ,
95
94
96
- #[ snafu ( display ( "Error getting complete multipart response body: {}" , source) ) ]
95
+ #[ error ( "Error getting complete multipart response body: {}" , source) ]
97
96
CompleteMultipartResponseBody { source : reqwest:: Error } ,
98
97
99
- #[ snafu ( display ( "Got invalid multipart response: {}" , source) ) ]
98
+ #[ error ( "Got invalid multipart response: {}" , source) ]
100
99
InvalidMultipartResponse { source : quick_xml:: de:: DeError } ,
101
100
102
- #[ snafu ( display ( "Error signing blob: {}" , source) ) ]
101
+ #[ error ( "Error signing blob: {}" , source) ]
103
102
SignBlobRequest { source : crate :: client:: retry:: Error } ,
104
103
105
- #[ snafu ( display ( "Got invalid signing blob response: {}" , source) ) ]
104
+ #[ error ( "Got invalid signing blob response: {}" , source) ]
106
105
InvalidSignBlobResponse { source : reqwest:: Error } ,
107
106
108
- #[ snafu ( display ( "Got invalid signing blob signature: {}" , source) ) ]
107
+ #[ error ( "Got invalid signing blob signature: {}" , source) ]
109
108
InvalidSignBlobSignature { source : base64:: DecodeError } ,
110
109
}
111
110
@@ -233,15 +232,17 @@ impl<'a> Request<'a> {
233
232
. payload ( self . payload )
234
233
. send ( )
235
234
. await
236
- . context ( RequestSnafu {
237
- path : self . path . as_ref ( ) ,
235
+ . map_err ( |source| {
236
+ let path = self . path . as_ref ( ) . into ( ) ;
237
+ Error :: Request { source, path }
238
238
} ) ?;
239
239
Ok ( resp)
240
240
}
241
241
242
242
async fn do_put ( self ) -> Result < PutResult > {
243
243
let response = self . send ( ) . await ?;
244
- Ok ( get_put_result ( response. headers ( ) , VERSION_HEADER ) . context ( MetadataSnafu ) ?)
244
+ Ok ( get_put_result ( response. headers ( ) , VERSION_HEADER )
245
+ . map_err ( |source| Error :: Metadata { source } ) ?)
245
246
}
246
247
}
247
248
@@ -333,17 +334,17 @@ impl GoogleCloudStorageClient {
333
334
. idempotent ( true )
334
335
. send ( )
335
336
. await
336
- . context ( SignBlobRequestSnafu ) ?;
337
+ . map_err ( |source| Error :: SignBlobRequest { source } ) ?;
337
338
338
339
//If successful, the signature is returned in the signedBlob field in the response.
339
340
let response = response
340
341
. json :: < SignBlobResponse > ( )
341
342
. await
342
- . context ( InvalidSignBlobResponseSnafu ) ?;
343
+ . map_err ( |source| Error :: InvalidSignBlobResponse { source } ) ?;
343
344
344
345
let signed_blob = BASE64_STANDARD
345
346
. decode ( response. signed_blob )
346
- . context ( InvalidSignBlobSignatureSnafu ) ?;
347
+ . map_err ( |source| Error :: InvalidSignBlobSignature { source } ) ?;
347
348
348
349
Ok ( hex_encode ( & signed_blob) )
349
350
}
@@ -386,7 +387,7 @@ impl GoogleCloudStorageClient {
386
387
PutMode :: Overwrite => builder. idempotent ( true ) ,
387
388
PutMode :: Create => builder. header ( & VERSION_MATCH , "0" ) ,
388
389
PutMode :: Update ( v) => {
389
- let etag = v. version . as_ref ( ) . context ( MissingVersionSnafu ) ?;
390
+ let etag = v. version . as_ref ( ) . ok_or ( Error :: MissingVersion ) ?;
390
391
builder. header ( & VERSION_MATCH , etag)
391
392
}
392
393
} ;
@@ -440,9 +441,14 @@ impl GoogleCloudStorageClient {
440
441
. send ( )
441
442
. await ?;
442
443
443
- let data = response. bytes ( ) . await . context ( PutResponseBodySnafu ) ?;
444
+ let data = response
445
+ . bytes ( )
446
+ . await
447
+ . map_err ( |source| Error :: PutResponseBody { source } ) ?;
448
+
444
449
let result: InitiateMultipartUploadResult =
445
- quick_xml:: de:: from_reader ( data. as_ref ( ) . reader ( ) ) . context ( InvalidPutResponseSnafu ) ?;
450
+ quick_xml:: de:: from_reader ( data. as_ref ( ) . reader ( ) )
451
+ . map_err ( |source| Error :: InvalidPutResponse { source } ) ?;
446
452
447
453
Ok ( result. upload_id )
448
454
}
@@ -464,8 +470,9 @@ impl GoogleCloudStorageClient {
464
470
. query ( & [ ( "uploadId" , multipart_id) ] )
465
471
. send_retry ( & self . config . retry_config )
466
472
. await
467
- . context ( RequestSnafu {
468
- path : path. as_ref ( ) ,
473
+ . map_err ( |source| {
474
+ let path = path. as_ref ( ) . into ( ) ;
475
+ Error :: Request { source, path }
469
476
} ) ?;
470
477
471
478
Ok ( ( ) )
@@ -495,7 +502,7 @@ impl GoogleCloudStorageClient {
495
502
let credential = self . get_credential ( ) . await ?;
496
503
497
504
let data = quick_xml:: se:: to_string ( & upload_info)
498
- . context ( InvalidPutResponseSnafu ) ?
505
+ . map_err ( |source| Error :: InvalidPutResponse { source } ) ?
499
506
// We cannot disable the escaping that transforms "/" to ""e;" :(
500
507
// https://github.com/tafia/quick-xml/issues/362
501
508
// https://github.com/tafia/quick-xml/issues/350
@@ -511,17 +518,18 @@ impl GoogleCloudStorageClient {
511
518
. idempotent ( true )
512
519
. send ( )
513
520
. await
514
- . context ( CompleteMultipartRequestSnafu ) ?;
521
+ . map_err ( |source| Error :: CompleteMultipartRequest { source } ) ?;
515
522
516
- let version = get_version ( response. headers ( ) , VERSION_HEADER ) . context ( MetadataSnafu ) ?;
523
+ let version = get_version ( response. headers ( ) , VERSION_HEADER )
524
+ . map_err ( |source| Error :: Metadata { source } ) ?;
517
525
518
526
let data = response
519
527
. bytes ( )
520
528
. await
521
- . context ( CompleteMultipartResponseBodySnafu ) ?;
529
+ . map_err ( |source| Error :: CompleteMultipartResponseBody { source } ) ?;
522
530
523
- let response: CompleteMultipartUploadResult =
524
- quick_xml :: de :: from_reader ( data . reader ( ) ) . context ( InvalidMultipartResponseSnafu ) ?;
531
+ let response: CompleteMultipartUploadResult = quick_xml :: de :: from_reader ( data . reader ( ) )
532
+ . map_err ( |source| Error :: InvalidMultipartResponse { source } ) ?;
525
533
526
534
Ok ( PutResult {
527
535
e_tag : Some ( response. e_tag ) ,
@@ -612,8 +620,9 @@ impl GetClient for GoogleCloudStorageClient {
612
620
. with_get_options ( options)
613
621
. send_retry ( & self . config . retry_config )
614
622
. await
615
- . context ( GetRequestSnafu {
616
- path : path. as_ref ( ) ,
623
+ . map_err ( |source| {
624
+ let path = path. as_ref ( ) . into ( ) ;
625
+ Error :: GetRequest { source, path }
617
626
} ) ?;
618
627
619
628
Ok ( response)
@@ -662,13 +671,13 @@ impl ListClient for GoogleCloudStorageClient {
662
671
. bearer_auth ( & credential. bearer )
663
672
. send_retry ( & self . config . retry_config )
664
673
. await
665
- . context ( ListRequestSnafu ) ?
674
+ . map_err ( |source| Error :: ListRequest { source } ) ?
666
675
. bytes ( )
667
676
. await
668
- . context ( ListResponseBodySnafu ) ?;
677
+ . map_err ( |source| Error :: ListResponseBody { source } ) ?;
669
678
670
- let mut response: ListResponse =
671
- quick_xml :: de :: from_reader ( response . reader ( ) ) . context ( InvalidListResponseSnafu ) ?;
679
+ let mut response: ListResponse = quick_xml :: de :: from_reader ( response . reader ( ) )
680
+ . map_err ( |source| Error :: InvalidListResponse { source } ) ?;
672
681
673
682
let token = response. next_continuation_token . take ( ) ;
674
683
Ok ( ( response. try_into ( ) ?, token) )
0 commit comments