@@ -47,13 +47,10 @@ function download_artefact(
47
47
. then ( ( response ) => {
48
48
response_code = response . status ;
49
49
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 ) ;
55
52
56
- response . data . on ( 'end ' , function ( ) {
53
+ writer . on ( 'finish ' , function ( ) {
57
54
if ( response_code == 200 ) {
58
55
const zip = new StreamZip ( { file : file_path } ) ;
59
56
zip . on ( "ready" , ( ) => {
@@ -70,13 +67,20 @@ function download_artefact(
70
67
}
71
68
} ) ;
72
69
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
+
73
76
} )
74
77
. catch ( ( error ) => {
75
78
76
79
if ( error . response ) {
77
80
resp = error . response
78
81
// The request was made and the server responded with a status code
79
82
// that falls out of the range of 2xx
83
+ console . log ( "Got error:" , error . response ) ;
80
84
if ( error . response . status == 401 ) {
81
85
resolve ( "Unauthorized" ) ;
82
86
} else {
@@ -93,8 +97,10 @@ function download_artefact(
93
97
reject ( "Could not download artefacts for test id " + test_id ) ;
94
98
}
95
99
} else if ( error . request ) {
100
+ console . log ( "Got error: error in request" , error . toJSON ( ) ) ;
96
101
console . log ( error . cause ) ;
97
102
} else {
103
+ console . log ( "Got error:" , error . toJSON ( ) ) ;
98
104
reject ( error ) ;
99
105
}
100
106
@@ -144,11 +150,13 @@ function generate_report(args) {
144
150
}
145
151
args . session_id = lambda_run_obj . session_id ;
146
152
} catch ( e ) {
153
+ console . log ( "Got error4 " , error . response ) ;
147
154
reject (
148
155
"Error!! lambdatest_run.json file is tampered Err: " + e . message
149
156
) ;
150
157
}
151
158
} else {
159
+ console . log ( "Got error5" , error . response ) ;
152
160
reject (
153
161
"Error!! Last session details not found, lambdatest_run.json file not present!!"
154
162
) ;
@@ -217,6 +225,7 @@ function generate_report(args) {
217
225
const downloadPromises = [ ] ;
218
226
219
227
for ( i = 0 ; i < build_info [ "data" ] . length ; i ++ ) {
228
+ console . log ( "Downloading artefacts for " , build_info [ "data" ] [ i ] [ "test_id" ] ) ;
220
229
const downloadPromise = download_artefact (
221
230
username ,
222
231
access_key ,
@@ -247,7 +256,7 @@ function generate_report(args) {
247
256
} )
248
257
. catch ( ( error ) => {
249
258
// This catch block will not be executed
250
- console . log ( error ) ;
259
+ console . log ( "Error7" , error ) ;
251
260
resolve ( "Done" ) ;
252
261
} ) ;
253
262
0 commit comments