Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Ignore errors resulting from printing to stdout.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Sep 24, 2016
1 parent 07d14b7 commit e3f8631
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dopt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::error::Error as StdError;
use std::fmt::{self, Debug};
use std::io::{self, Write};
use std::str::FromStr;

use regex::{Captures, Regex};
Expand Down Expand Up @@ -107,7 +108,7 @@ impl Error {
werr!("{}\n", self);
::std::process::exit(1)
} else {
println!("{}", self);
let _ = writeln!(&mut io::stdout(), "{}", self);
::std::process::exit(0)
}
}
Expand Down

2 comments on commit e3f8631

@balta2ar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BurntSushi I'm new to rust and I couldn't find what's the best way to catch Broken pipe error in rust 1.11 stable. Do I get it right that this change simply ignores the error but the loop continues running? Is there a way to catch pipe error and terminate execution without printing a stack trace? This is for my own rust education.

@BurntSushi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right to point out that I was being a little careless here. While this does avoid panicing on a pipe error, it also avoids handling any other kind of error too.

In xsv I was a bit more fastidious about this, and handled the pipe error explicitly: https://github.com/BurntSushi/xsv/blob/master/src/main.rs#L122-L125

Please sign in to comment.