@@ -222,23 +222,45 @@ impl CardanoDbVerifyCommand {
222222 . collect :: < Vec < _ > > ( )
223223 . join ( "\n - " )
224224 }
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+ }
227233
228234 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+
229246 let json = serde_json:: json!( {
230247 "timestamp" : Utc :: now( ) . to_rfc3339( ) ,
231248 "verify_error" : {
232249 "message" : "Verifying immutables files has failed" ,
233250 "immutables_dir" : lists. immutables_dir,
234251 "missing_files_count" : lists. missing. len( ) ,
235252 "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 ,
238255 }
239256 } ) ;
240257 println ! ( "{json}" ) ;
258+ write_json_file_error ( lists) ;
241259 } 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 ) ;
242264 if !lists. missing . is_empty ( ) {
243265 println ! ( "Verifying immutables files has failed:" ) ;
244266 println ! ( "Number of missing immutable files: {}" , lists. missing. len( ) ) ;
@@ -260,6 +282,21 @@ impl CardanoDbVerifyCommand {
260282 }
261283}
262284
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+
263300fn print_immutables_range_to_verify (
264301 cardano_db_message : & CardanoDatabaseSnapshot ,
265302 immutable_file_range : & ImmutableFileRange ,
0 commit comments