Better handle cancellation

This commit is contained in:
Gregory 2020-06-12 14:56:30 -04:00
parent 3ce7a69d46
commit 29534ae341
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2
3 changed files with 17 additions and 6 deletions

View file

@ -57,6 +57,10 @@ impl Config {
output.trim_end().to_owned()
};
Ok(output)
if output.is_empty() {
Err(Error::Cancelled)
} else {
Ok(output)
}
}
}

View file

@ -22,6 +22,8 @@ pub enum Error {
MimeDetect(#[from] mime_detective::DetectiveError),
#[error("error spawning selector process '{0}'")]
Selector(String),
#[error("selection cancelled")]
Cancelled,
}
pub type Result<T, E = Error> = std::result::Result<T, E>;

View file

@ -54,14 +54,19 @@ fn main() -> Result<()> {
}();
match (res, atty::is(atty::Stream::Stdout)) {
(Err(e), true) => eprintln!("{}", e),
(Err(e), _) if matches!(e, Error::Cancelled) => {
std::process::exit(1);
}
(Err(e), true) => {
eprintln!("{}", e);
std::process::exit(1);
}
(Err(e), false) => {
std::process::Command::new("notify-send")
.args(&["handlr error", &e.to_string()])
.spawn()?;
std::process::exit(1);
}
_ => {}
};
Ok(())
_ => Ok(()),
}
}