@@ -11,7 +11,7 @@ use super::{clang, json};
1111use crate :: { intercept, semantic} ;
1212use serde_json:: de:: IoRead ;
1313use serde_json:: StreamDeserializer ;
14- use std:: { io , path } ;
14+ use std:: io ;
1515use thiserror:: Error ;
1616
1717/// The trait represents a file format that can be written to and read from.
@@ -25,11 +25,14 @@ pub trait FileFormat<T> {
2525
2626 /// Reads the entries from the file and ignores any errors.
2727 /// This is not always feasible, when the file format is strict.
28- fn read_and_ignore ( reader : impl io:: Read , source : path:: PathBuf ) -> impl Iterator < Item = T > {
28+ fn read_and_ignore (
29+ reader : impl io:: Read ,
30+ message_writer : impl Fn ( & str ) ,
31+ ) -> impl Iterator < Item = T > {
2932 Self :: read ( reader) . filter_map ( move |result| match result {
3033 Ok ( value) => Some ( value) ,
3134 Err ( error) => {
32- log :: warn! ( "Failed to read entry: {:?} from {:?}" , error, source ) ;
35+ message_writer ( & error. to_string ( ) ) ;
3336 None
3437 }
3538 } )
@@ -400,7 +403,6 @@ mod test {
400403 use serde_json:: json;
401404 use std:: collections:: HashMap ;
402405 use std:: io:: { Cursor , Seek , SeekFrom } ;
403- use std:: path:: PathBuf ;
404406
405407 #[ test]
406408 fn read_write ( ) {
@@ -453,13 +455,17 @@ mod test {
453455 }
454456 } ) ;
455457 let content = format ! ( "{}\n {}\n {}\n " , line1, line2, line3) ;
456- let source = PathBuf :: from ( "/home/user/project.json" ) ;
457458
458459 let mut cursor = Cursor :: new ( content) ;
459- let read_events: Vec < _ > = Sut :: read_and_ignore ( & mut cursor, source) . collect ( ) ;
460+ let warnings = std:: cell:: RefCell :: new ( Vec :: new ( ) ) ;
461+ let read_events: Vec < _ > = Sut :: read_and_ignore ( & mut cursor, |error| {
462+ warnings. borrow_mut ( ) . push ( format ! ( "Warning: {:?}" , error) ) ;
463+ } )
464+ . collect ( ) ;
460465
461- // Only the fist event is read, all other lines are ignored.
466+ // Only the first event is read, all other lines are ignored.
462467 assert_eq ! ( expected_values( ) [ 0 ..1 ] , read_events) ;
468+ assert_eq ! ( warnings. borrow( ) . len( ) , 1 ) ;
463469 }
464470
465471 fn expected_values ( ) -> Vec < Event > {
0 commit comments