Closed lelandjansen closed 5 years ago
I recently removed failure from one of my crates too, perhaps we ought to get rid of it here
@lelandjansen could you give the branch feature/error-interface
a try? if that's find we could call that 0.3.0
@lelandjansen could you give the branch feature/error-interface a try?
@hoodie lgtm
Thank you for getting together this PR! I tested your change on the test program below as well as my own project.
# Cargo.toml
[package]
name = "notifications"
version = "0.1.0"
authors = ["Leland Jansen <hello@lelandjansen.com>"]
edition = "2018"
[dependencies]
mac-notification-sys = { git = "https://github.com/hoodie/mac-notification-sys", branch = "feature/error-interface" }
// src/lib.rs
use std::fmt;
use std::error;
#[derive(Debug)]
pub enum MyError {
MacOs(mac_notification_sys::error::Error),
}
fn notify() -> Result<(), MyError> {
mac_notification_sys::send_notification("Test", &None, "Testing...", &None)?;
Ok(())
}
impl error::Error for MyError {}
impl fmt::Display for MyError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", self)
}
}
impl From<mac_notification_sys::error::Error> for MyError {
fn from(err: mac_notification_sys::error::Error) -> Self {
MyError::MacOs(err)
}
}
mod test {
use super::*;
#[test]
fn notifies() {
assert!(notify().is_ok());
}
}
Resolved by #12.
The rust-lang-nursery/failure crate provides convenient error handling in Rust and was recently used by
mac-notification-sys
inv0.2
. However, returning afailure::error::Error
in public methods such assend_notification
forces clients who wish to handle the error without callingunwrap()
to use thefailure
crate and add it as a project dependency. This ticket is a recommendation/request to remove thefailure
dependency and revert to theerror_chain
handling inv0.1.*
(or vanilla error handling).One workaround would be to use
map_err
and pass thedisplay
message to our own type, but this is not optimal.Thanks for the awesome crate :)