@@ -2,7 +2,7 @@ use std::{fmt, sync::Arc, time::Duration};
22
33use rama:: {
44 Service ,
5- error:: { ErrorContext , OpaqueError } ,
5+ error:: { BoxError , ErrorContext } ,
66 graceful:: ShutdownGuard ,
77 http:: {
88 BodyExtractExt , Request , Response , StatusCode , Uri , service:: client:: HttpClientExt as _,
@@ -13,7 +13,7 @@ use rama::{
1313
1414use arc_swap:: { ArcSwap , Guard } ;
1515use radix_trie:: Trie ;
16- use rand:: Rng ;
16+ use rand:: RngExt as _ ;
1717use serde:: { Deserialize , Serialize } ;
1818use tokio:: time:: Instant ;
1919
@@ -55,9 +55,9 @@ impl RemoteMalwareList {
5555 sync_storage : SyncCompactDataStorage ,
5656 client : C ,
5757 formatter : Option < EntryFormatter > ,
58- ) -> Result < Self , OpaqueError >
58+ ) -> Result < Self , BoxError >
5959 where
60- C : Service < Request , Output = Response , Error = OpaqueError > ,
60+ C : Service < Request , Output = Response , Error = BoxError > ,
6161 {
6262 let entry_formatter = formatter. unwrap_or_else ( || Arc :: new ( IdentityEntryFormatter ) ) ;
6363
@@ -132,12 +132,12 @@ struct RemoteMalwareListClient<C> {
132132
133133impl < C > RemoteMalwareListClient < C >
134134where
135- C : Service < Request , Output = Response , Error = OpaqueError > ,
135+ C : Service < Request , Output = Response , Error = BoxError > ,
136136{
137137 async fn download_malware_trie (
138138 & self ,
139139 e_tag : Option < & str > ,
140- ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , OpaqueError > {
140+ ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , BoxError > {
141141 let Some ( ( malware_list, new_e_tag) ) =
142142 self . fetch_remote_malware_list_and_e_tag ( e_tag) . await ?
143143 else {
@@ -159,7 +159,7 @@ where
159159 async fn fetch_remote_malware_list_and_e_tag (
160160 & self ,
161161 previous_e_tag : Option < & str > ,
162- ) -> Result < Option < ( Vec < ListDataEntry > , Option < ArcStr > ) > , OpaqueError > {
162+ ) -> Result < Option < ( Vec < ListDataEntry > , Option < ArcStr > ) > , BoxError > {
163163 let start = Instant :: now ( ) ;
164164
165165 let req_builder = self . client . get ( self . uri . clone ( ) ) ;
@@ -170,13 +170,12 @@ where
170170 req_builder
171171 } ;
172172
173- let resp = req_builder. send ( ) . await . with_context ( || {
174- format ! (
175- "fetch malware list from remote endpoint '{}'; (tt: {:?})" ,
176- self . uri,
177- start. elapsed( )
178- )
179- } ) ?;
173+ let resp = req_builder
174+ . send ( )
175+ . await
176+ . context ( "fetch malware list from remote endpoint" )
177+ . context_debug_field ( "tt" , start. elapsed ( ) )
178+ . with_context_field ( "uri" , || self . uri . clone ( ) ) ?;
180179
181180 if resp. status ( ) == StatusCode :: NOT_MODIFIED {
182181 tracing:: debug!(
@@ -195,13 +194,9 @@ where
195194 let malware_list: Vec < ListDataEntry > = resp
196195 . try_into_json ( )
197196 . await
198- . with_context ( || {
199- format ! (
200- "collect and json-decode malware list response payload from remote endpoint '{}'; (tt: {:?})" ,
201- self . uri,
202- start. elapsed( ) ,
203- )
204- } ) ?;
197+ . context ( "collect and json-decode malware list response payload from remote endpoint" )
198+ . with_context_field ( "uri" , || self . uri . clone ( ) )
199+ . with_context_debug_field ( "tt" , || start. elapsed ( ) ) ?;
205200
206201 tracing:: debug!(
207202 "fetched and decoded and new malware list from remote endpoint '{}', with {} entries (tt: {:?})" ,
@@ -239,34 +234,24 @@ where
239234
240235 async fn load_cached_malware_trie (
241236 & self ,
242- ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , OpaqueError > {
237+ ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , BoxError > {
243238 tokio:: task:: spawn_blocking ( {
244239 let storage = self . sync_storage . clone ( ) ;
245240 let filename = self . filename . clone ( ) ;
246241 let formatter = self . formatter . clone ( ) ;
247242 move || load_cached_malware_trie_sync_inner ( storage, filename, formatter. as_ref ( ) )
248243 } )
249244 . await
250- . with_context ( || {
251- format ! (
252- "wait for blocking task to use cached malware list for creating new remote malware list (failure endpoint: {})" ,
253- self . uri
254- )
255- } ) ?
256- . with_context ( || {
257- format ! (
258- "try to use cached malware list for creating new remote malware list (failure endpoint: {})" ,
259- self . uri
260- )
261- } )
245+ . context ( "wait for blocking task to use cached malware list for creating new remote malware list" )
246+ . with_context_field ( "uri" , || self . uri . clone ( ) ) ?
262247 }
263248}
264249
265250fn load_cached_malware_trie_sync_inner (
266251 storage : SyncCompactDataStorage ,
267252 filename : ArcStr ,
268253 formatter : & dyn MalwareListEntryFormatter ,
269- ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , OpaqueError > {
254+ ) -> Result < Option < ( MalwareTrie , Option < ArcStr > ) > , BoxError > {
270255 let cached_malware_trie: Option < CachedMalwareTrie > =
271256 storage. load ( & filename) . context ( "storage failure" ) ?;
272257
@@ -285,7 +270,7 @@ async fn remote_list_update_loop<C>(
285270 e_tag : Option < ArcStr > ,
286271 shared_malware_trie : Arc < ArcSwap < MalwareTrie > > ,
287272) where
288- C : Service < Request , Output = Response , Error = OpaqueError > ,
273+ C : Service < Request , Output = Response , Error = BoxError > ,
289274{
290275 tracing:: debug!(
291276 "remote malware list (uri = {}), update loop task up and running" ,
0 commit comments