@@ -148,29 +148,42 @@ where
148148 . into_reflection ( ) // I really want to use std::mem::transmute here but can't.
149149 . par_convert_names_to_utf8 ( ) // TODO: allow non-UTF8 somehow.
150150 . expect ( "convert all names from raw string to UTF-8" ) ;
151- let shared = if !shared_details && !shared_summary {
152- JsonShared :: default ( )
151+
152+ let deduplication_result = if !shared_details && !shared_summary {
153+ Ok ( JsonShared :: default ( ) )
153154 } else {
154- let mut shared = deduplication_record
155- . map_err ( HardlinksHandler :: convert_error) ?
156- . pipe ( HardlinksHandler :: json_report) ?
157- . unwrap_or_default ( ) ;
158- if !shared_details {
159- shared. details = None ;
160- }
161- if !shared_summary {
162- shared. summary = None ;
163- }
164- shared
155+ // `try` expression would be extremely useful right now but it sadly requires nightly
156+ || -> Result < _ , RuntimeError > {
157+ let mut shared = deduplication_record
158+ . map_err ( HardlinksHandler :: convert_error) ?
159+ . pipe ( HardlinksHandler :: json_report) ?
160+ . unwrap_or_default ( ) ;
161+ if !shared_details {
162+ shared. details = None ;
163+ }
164+ if !shared_summary {
165+ shared. summary = None ;
166+ }
167+ Ok ( shared)
168+ } ( )
165169 } ;
170+
171+ // errors caused by failing deduplication shouldn't prevent the JSON data from being printed
172+ let ( shared, deduplication_result) = match deduplication_result {
173+ Ok ( shared) => ( shared, Ok ( ( ) ) ) ,
174+ Err ( error) => ( JsonShared :: default ( ) , Err ( error) ) ,
175+ } ;
176+
166177 let json_tree = JsonTree { tree, shared } ;
167178 let json_data = JsonData {
168179 schema_version : SchemaVersion ,
169180 binary_version : Some ( BinaryVersion :: current ( ) ) ,
170181 body : json_tree. into ( ) ,
171182 } ;
183+
172184 return serde_json:: to_writer ( stdout ( ) , & json_data)
173- . map_err ( RuntimeError :: SerializationFailure ) ;
185+ . map_err ( RuntimeError :: SerializationFailure )
186+ . or ( deduplication_result) ;
174187 }
175188
176189 let visualizer = Visualizer {
0 commit comments