[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 04/25] tools/xenbindgen: Add a TOML spec reader



On Mon Nov 25, 2024 at 3:13 PM GMT, Teddy Astie wrote:
> Hi,
>
> > +    let _specification = match spec::Spec::new(&cli.indir) {
> > +        Ok(x) => x,
> > +        Err(spec::Error::Toml(x)) => {
> > +            error!("TOML parsing error:");
> > +            error!("{x:#?}");
> > +            std::process::exit(1);
> > +        }
> > +        Err(spec::Error::Io(x)) => {
> > +            error!("IO error:");
> > +            error!("{x:#?}");
> > +            std::process::exit(1);
> > +        }
> > +    };
>
> I think it can be replaced with .unwrap() (or making the main function 
> returns a Result<T, E>) as long as our internal error implements Display.

Oh, I wasn't aware E: Display was honoured on exit. I thought it always used E:
Debug. That ought to be a lot nicer.

>
> > +/// Internal error type for every error spec parsing could encounter
> > +#[derive(Debug)]
> > +pub enum Error {
> > +    /// Wrapper around IO errors
> > +    Io(std::io::Error),
> > +    /// Wrapper around deserialization errors
> > +    Toml(toml::de::Error),
> > +}
> > +
> > +/// Maps an [`std::io::Error`] onto a [`Error`] type for easier propagation
> > +fn from_ioerr<T>(t: std::io::Result<T>) -> Result<T, Error> {
> > +    t.map_err(Error::Io)
> > +}
> > +
>
> May be worth a
> impl From<std::io::Error> for super::Error
> such as ? operator can automatically convert it to our internal error type
>
> Cheers
> Teddy
>
>
> Teddy Astie | Vates XCP-ng Developer
>
> XCP-ng & Xen Orchestra - Vates solutions
>
> web: https://vates.tech

Yes, I replaced all this faff in my internal branch with From<std::io::Error>
and From<toml::de::Error> shortly after sending the RFC. It is indeed a lot
tidier.

Cheers,
Alejandro




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.