@@ -47,13 +47,10 @@ function download_artefact(
4747 . then ( ( response ) => {
4848 response_code = response . status ;
4949 resp = response ;
50- response . data . pipe (
51- fs . createWriteStream ( file_path , {
52- overwrite : true ,
53- } )
54- ) ;
50+ const writer = fs . createWriteStream ( file_path , { overwrite : true , } ) ;
51+ response . data . pipe ( writer ) ;
5552
56- response . data . on ( 'end ' , function ( ) {
53+ writer . on ( 'finish ' , function ( ) {
5754 if ( response_code == 200 ) {
5855 const zip = new StreamZip ( { file : file_path } ) ;
5956 zip . on ( "ready" , ( ) => {
@@ -70,13 +67,20 @@ function download_artefact(
7067 }
7168 } ) ;
7269
70+ writer . on ( 'error' , ( err ) => {
71+ console . error ( 'Error writing to file:' , err ) ;
72+ fs . unlinkSync ( file_path ) ; // Cleanup on error
73+ reject ( 'Error writing to file for test id ' + test_id ) ;
74+ } ) ;
75+
7376 } )
7477 . catch ( ( error ) => {
7578
7679 if ( error . response ) {
7780 resp = error . response
7881 // The request was made and the server responded with a status code
7982 // that falls out of the range of 2xx
83+ console . log ( "Got error:" , error . response ) ;
8084 if ( error . response . status == 401 ) {
8185 resolve ( "Unauthorized" ) ;
8286 } else {
@@ -93,8 +97,10 @@ function download_artefact(
9397 reject ( "Could not download artefacts for test id " + test_id ) ;
9498 }
9599 } else if ( error . request ) {
100+ console . log ( "Got error: error in request" , error . toJSON ( ) ) ;
96101 console . log ( error . cause ) ;
97102 } else {
103+ console . log ( "Got error:" , error . toJSON ( ) ) ;
98104 reject ( error ) ;
99105 }
100106
@@ -144,11 +150,13 @@ function generate_report(args) {
144150 }
145151 args . session_id = lambda_run_obj . session_id ;
146152 } catch ( e ) {
153+ console . log ( "Got error4 " , error . response ) ;
147154 reject (
148155 "Error!! lambdatest_run.json file is tampered Err: " + e . message
149156 ) ;
150157 }
151158 } else {
159+ console . log ( "Got error5" , error . response ) ;
152160 reject (
153161 "Error!! Last session details not found, lambdatest_run.json file not present!!"
154162 ) ;
@@ -217,6 +225,7 @@ function generate_report(args) {
217225 const downloadPromises = [ ] ;
218226
219227 for ( i = 0 ; i < build_info [ "data" ] . length ; i ++ ) {
228+ console . log ( "Downloading artefacts for " , build_info [ "data" ] [ i ] [ "test_id" ] ) ;
220229 const downloadPromise = download_artefact (
221230 username ,
222231 access_key ,
@@ -247,7 +256,7 @@ function generate_report(args) {
247256 } )
248257 . catch ( ( error ) => {
249258 // This catch block will not be executed
250- console . log ( error ) ;
259+ console . log ( "Error7" , error ) ;
251260 resolve ( "Done" ) ;
252261 } ) ;
253262
0 commit comments