@@ -21,7 +21,7 @@ pub async fn download_tsv_file(config: &Config) -> Result<(), String> {
2121 println ! ( "{}" , e. to_string( ) ) ;
2222 } ) ;
2323
24- let remote_sha_url = config. expected_remote_stacks_tsv_sha256 ( ) ;
24+ let remote_sha_url = config. expected_remote_stacks_tsv_sha256 ( ) ? ;
2525 let res = reqwest:: get ( & remote_sha_url)
2626 . await
2727 . or ( Err ( format ! ( "Failed to GET from '{}'" , & remote_sha_url) ) ) ?
@@ -34,7 +34,7 @@ pub async fn download_tsv_file(config: &Config) -> Result<(), String> {
3434
3535 write_file_content_at_path ( & local_sha_file_path, & res. to_vec ( ) ) ?;
3636
37- let file_url = config. expected_remote_stacks_tsv_url ( ) ;
37+ let file_url = config. expected_remote_stacks_tsv_url ( ) ? ;
3838 let res = reqwest:: get ( & file_url)
3939 . await
4040 . or ( Err ( format ! ( "Failed to GET from '{}'" , & file_url) ) ) ?;
@@ -55,14 +55,17 @@ pub async fn download_tsv_file(config: &Config) -> Result<(), String> {
5555 Ok ( 0 ) => break ,
5656 Ok ( n) => {
5757 if let Err ( e) = file. write_all ( & buffer[ ..n] ) {
58- let err =
59- format ! ( "unable to update compressed archive: {}" , e. to_string( ) ) ;
60- return Err ( err) ;
58+ return Err ( format ! (
59+ "unable to update compressed archive: {}" ,
60+ e. to_string( )
61+ ) ) ;
6162 }
6263 }
6364 Err ( e) => {
64- let err = format ! ( "unable to write compressed archive: {}" , e. to_string( ) ) ;
65- return Err ( err) ;
65+ return Err ( format ! (
66+ "unable to write compressed archive: {}" ,
67+ e. to_string( )
68+ ) ) ;
6669 }
6770 }
6871 }
@@ -83,12 +86,11 @@ pub async fn download_tsv_file(config: &Config) -> Result<(), String> {
8386 . map_err ( |e| format ! ( "unable to download stacks archive: {}" , e. to_string( ) ) ) ?;
8487 }
8588 drop ( tx) ;
86-
8789 tokio:: task:: spawn_blocking ( || decoder_thread. join ( ) )
8890 . await
89- . unwrap ( )
90- . unwrap ( )
91- . unwrap ( ) ;
91+ . map_err ( |e| format ! ( "failed to spawn thread: {e}" ) ) ?
92+ . map_err ( |e| format ! ( "decoder thread failed when downloading tsv: {:?}" , e ) ) ?
93+ . map_err ( |e| format ! ( "failed to download tsv: {}" , e ) ) ? ;
9294 }
9395
9496 Ok ( ( ) )
@@ -124,11 +126,14 @@ impl Read for ChannelRead {
124126 }
125127}
126128
127- pub async fn download_stacks_dataset_if_required ( config : & mut Config , ctx : & Context ) -> bool {
129+ pub async fn download_stacks_dataset_if_required (
130+ config : & mut Config ,
131+ ctx : & Context ,
132+ ) -> Result < bool , String > {
128133 if config. is_initial_ingestion_required ( ) {
129134 // Download default tsv.
130135 if config. rely_on_remote_stacks_tsv ( ) && config. should_download_remote_stacks_tsv ( ) {
131- let url = config. expected_remote_stacks_tsv_url ( ) ;
136+ let url = config. expected_remote_stacks_tsv_url ( ) ? ;
132137 let mut tsv_file_path = config. expected_cache_path ( ) ;
133138 tsv_file_path. push ( default_tsv_file_path ( & config. network . stacks_network ) ) ;
134139 let mut tsv_sha_file_path = config. expected_cache_path ( ) ;
@@ -137,7 +142,7 @@ pub async fn download_stacks_dataset_if_required(config: &mut Config, ctx: &Cont
137142 // Download archive if not already present in cache
138143 // Load the local
139144 let local_sha_file = read_file_content_at_path ( & tsv_sha_file_path) ;
140- let sha_url = config. expected_remote_stacks_tsv_sha256 ( ) ;
145+ let sha_url = config. expected_remote_stacks_tsv_sha256 ( ) ? ;
141146
142147 let remote_sha_file = match reqwest:: get ( & sha_url) . await {
143148 Ok ( response) => response. bytes ( ) . await ,
@@ -164,28 +169,25 @@ pub async fn download_stacks_dataset_if_required(config: &mut Config, ctx: &Cont
164169 "Stacks archive file already up to date"
165170 ) ;
166171 config. add_local_stacks_tsv_source ( & tsv_file_path) ;
167- return false ;
172+ return Ok ( false ) ;
168173 }
169174
170175 info ! ( ctx. expect_logger( ) , "Downloading {}" , url) ;
171176 match download_tsv_file ( & config) . await {
172177 Ok ( _) => { }
173- Err ( e) => {
174- error ! ( ctx. expect_logger( ) , "{}" , e) ;
175- std:: process:: exit ( 1 ) ;
176- }
178+ Err ( e) => return Err ( e) ,
177179 }
178180 info ! ( ctx. expect_logger( ) , "Successfully downloaded tsv file" ) ;
179181 config. add_local_stacks_tsv_source ( & tsv_file_path) ;
180182 }
181- true
183+ Ok ( true )
182184 } else {
183185 info ! (
184186 ctx. expect_logger( ) ,
185187 "Streaming blocks from stacks-node {}" ,
186188 config. network. get_stacks_node_config( ) . rpc_url
187189 ) ;
188- false
190+ Ok ( false )
189191 }
190192}
191193
0 commit comments