@@ -222,23 +222,45 @@ impl CardanoDbVerifyCommand {
222
222
. collect :: < Vec < _ > > ( )
223
223
. join ( "\n - " )
224
224
}
225
- let missing_files_subset = get_first_10_files_path ( & lists. missing , & lists. immutables_dir ) ;
226
- let tampered_files_subset = get_first_10_files_path ( & lists. tampered , & lists. immutables_dir ) ;
225
+
226
+ fn get_attribute_name ( subset_len : usize , subset_size : usize , base_name : & str ) -> String {
227
+ if subset_len > subset_size {
228
+ format ! ( "{base_name}-subset" )
229
+ } else {
230
+ base_name. to_string ( )
231
+ }
232
+ }
227
233
228
234
if json_output {
235
+ let subset_size = 100 ;
236
+ let missing_subset =
237
+ lists. missing . iter ( ) . take ( subset_size) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
238
+ let tampered_subset =
239
+ lists. tampered . iter ( ) . take ( subset_size) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
240
+
241
+ let missing_json_attribute =
242
+ get_attribute_name ( lists. missing . len ( ) , subset_size, "missing-files" ) ;
243
+ let tampered_json_attribute =
244
+ get_attribute_name ( lists. tampered . len ( ) , subset_size, "tampered-files" ) ;
245
+
229
246
let json = serde_json:: json!( {
230
247
"timestamp" : Utc :: now( ) . to_rfc3339( ) ,
231
248
"verify_error" : {
232
249
"message" : "Verifying immutables files has failed" ,
233
250
"immutables_dir" : lists. immutables_dir,
234
251
"missing_files_count" : lists. missing. len( ) ,
235
252
"tampered_files_count" : lists. tampered. len( ) ,
236
- "missing_files" : lists . missing ,
237
- "tampered_files" : lists . tampered ,
253
+ missing_json_attribute : missing_subset ,
254
+ tampered_json_attribute : tampered_subset ,
238
255
}
239
256
} ) ;
240
257
println ! ( "{json}" ) ;
258
+ write_json_file_error ( lists) ;
241
259
} else {
260
+ let missing_files_subset =
261
+ get_first_10_files_path ( & lists. missing , & lists. immutables_dir ) ;
262
+ let tampered_files_subset =
263
+ get_first_10_files_path ( & lists. tampered , & lists. immutables_dir ) ;
242
264
if !lists. missing . is_empty ( ) {
243
265
println ! ( "Verifying immutables files has failed:" ) ;
244
266
println ! ( "Number of missing immutable files: {}" , lists. missing. len( ) ) ;
@@ -260,6 +282,21 @@ impl CardanoDbVerifyCommand {
260
282
}
261
283
}
262
284
285
+ fn write_json_file_error ( lists : & ImmutableFilesLists ) {
286
+ //TODO erase file if multiple runs or generate UUID ?
287
+ let file_path = PathBuf :: from ( "immutables_verification_error.json" ) ;
288
+ std:: fs:: write (
289
+ & file_path,
290
+ serde_json:: to_string_pretty ( & serde_json:: json!( {
291
+ "timestamp" : Utc :: now( ) . to_rfc3339( ) ,
292
+ "missing-files" : lists. missing,
293
+ "tampered-files" : lists. tampered,
294
+ } ) )
295
+ . unwrap ( ) ,
296
+ )
297
+ . expect ( "Could not write immutables verification error to file" ) ;
298
+ }
299
+
263
300
fn print_immutables_range_to_verify (
264
301
cardano_db_message : & CardanoDatabaseSnapshot ,
265
302
immutable_file_range : & ImmutableFileRange ,
0 commit comments