epub-builder icon indicating copy to clipboard operation
epub-builder copied to clipboard

Replace error-chain with other error handling library

Open kpcyrd opened this issue 3 years ago • 3 comments

hi!

error-chain is no longer maintained and difficult to use with modern error handling libraries.

Could you replace it with a more modern one, like anyhow?

Thanks! :)

kpcyrd avatar Aug 15 '21 19:08 kpcyrd

To use anyhow with epub-builder I've used in src/errors.rs

use anyhow::anyhow;

pub trait EpubResultExt {
    type Ok;
    fn anyhow(self) -> anyhow::Result<Self::Ok>;
}

impl<T> EpubResultExt for Result<T, epub_builder::Error> {
    type Ok = T;
    fn anyhow(self) -> anyhow::Result<T> {
        self.map_err(|e| anyhow!("epub error: {:?}", e))
    }
}

In my program:

use errors:EpubResultExt
EpubBuilder::new(ZipLibrary::new().anyhow()?;

jelly avatar Aug 16 '21 19:08 jelly

To be honest I've been quite away from Rust (and any programming) in a while so I've not followed recent developments, I'll try to look into it but if someone is willing to make a PR it's more likely to be quicker :)

crowdagger avatar Aug 16 '21 21:08 crowdagger

No problem, left the comment here for others to find an way to work around the issue.

jelly avatar Aug 17 '21 06:08 jelly