Skip to content

Commit

Permalink
Fix unconditional recursion in <ctrlc::Error as fmt::Display>::fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Jul 29, 2020
1 parent b21c43c commit bf08402
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ pub enum Error {
System(std::io::Error),
}

impl Error {
fn describe(&self) -> &str {
match *self {
Error::NoSuchSignal(_) => "Signal could not be found from the system",
Error::MultipleHandlers => "Ctrl-C signal handler already registered",
Error::System(_) => "Unexpected system error",
}
}
}

impl From<::platform::Error> for Error {
fn from(e: ::platform::Error) -> Error {
let system_error = std::io::Error::new(std::io::ErrorKind::Other, e);
Expand All @@ -21,17 +31,13 @@ impl From<::platform::Error> for Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Ctrl-C error: {}", self)
write!(f, "Ctrl-C error: {}", self.describe())
}
}

impl std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::NoSuchSignal(_) => "Signal could not be found from the system",
Error::MultipleHandlers => "Ctrl-C signal handler already registered",
Error::System(_) => "Unexpected system error",
}
self.describe()
}

fn cause(&self) -> Option<&dyn std::error::Error> {
Expand Down

0 comments on commit bf08402

Please sign in to comment.