Skip to content

Commit 59876d9

Browse files
committed
exit(1) if writeln! to stdout fails
1 parent d351a82 commit 59876d9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

summarize/src/main.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,15 @@ fn diff(opt: DiffOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
142142

143143
table.printstd();
144144

145-
_ = writeln!(
145+
let res = writeln!(
146146
std::io::stdout(),
147147
"Total cpu time: {:?}",
148148
results.total_time
149149
);
150+
if res.is_err() {
151+
// there's something wrong with stdout - give up on writing more
152+
std::process::exit(1);
153+
}
150154

151155
let mut table = Table::new();
152156

@@ -290,18 +294,26 @@ fn summarize(opt: SummarizeOpt) -> Result<(), Box<dyn Error + Send + Sync>> {
290294

291295
table.printstd();
292296

293-
_ = writeln!(
297+
let res = writeln!(
294298
std::io::stdout(),
295299
"Total cpu time: {:?}",
296300
results.total_time
297301
);
302+
if res.is_err() {
303+
// there's something wrong with stdout - give up on writing more
304+
std::process::exit(1);
305+
}
298306

299307
if percent_above != 0.0 {
300-
_ = writeln!(
308+
let res = writeln!(
301309
std::io::stdout(),
302310
"Filtered results account for {:.3}% of total time.",
303311
percent_total_time
304312
);
313+
if res.is_err() {
314+
// there's something wrong with stdout - give up on writing more
315+
std::process::exit(1);
316+
}
305317
}
306318

307319
let mut table = Table::new();

0 commit comments

Comments
 (0)