mirror of
https://github.com/chmln/handlr.git
synced 2025-04-19 15:43:02 +02:00
Better handle cancellation
This commit is contained in:
parent
3ce7a69d46
commit
29534ae341
3 changed files with 17 additions and 6 deletions
|
@ -57,6 +57,10 @@ impl Config {
|
||||||
output.trim_end().to_owned()
|
output.trim_end().to_owned()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(output)
|
if output.is_empty() {
|
||||||
|
Err(Error::Cancelled)
|
||||||
|
} else {
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ pub enum Error {
|
||||||
MimeDetect(#[from] mime_detective::DetectiveError),
|
MimeDetect(#[from] mime_detective::DetectiveError),
|
||||||
#[error("error spawning selector process '{0}'")]
|
#[error("error spawning selector process '{0}'")]
|
||||||
Selector(String),
|
Selector(String),
|
||||||
|
#[error("selection cancelled")]
|
||||||
|
Cancelled,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -54,14 +54,19 @@ fn main() -> Result<()> {
|
||||||
}();
|
}();
|
||||||
|
|
||||||
match (res, atty::is(atty::Stream::Stdout)) {
|
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) => {
|
(Err(e), false) => {
|
||||||
std::process::Command::new("notify-send")
|
std::process::Command::new("notify-send")
|
||||||
.args(&["handlr error", &e.to_string()])
|
.args(&["handlr error", &e.to_string()])
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => Ok(()),
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue