source-foundry / ufofmt

A fast, flexible UFO source file formatter based on the Rust Norad library
Apache License 2.0
7 stars 1 forks source link

Create custom errors #11

Closed chrissimpkins closed 3 years ago

chrissimpkins commented 3 years ago

Hm, you may want to lean more on Rust for the errors. You can make your own error container like https://github.com/linebender/norad/blob/master/src/error.rs#L11-L47 and then implement Display for it for formatting them for printing: https://github.com/linebender/norad/blob/master/src/error.rs#L150-L201

Originally posted by @madig in https://github.com/source-foundry/ufofmt/issues/5#issuecomment-886249143

madig commented 3 years ago

There are also some other crates for easier error handling, see e.g. https://rust-cli.github.io/book/tutorial/errors.html.

chrissimpkins commented 3 years ago

Thoughts about whether we need to implement much of the custom error type / handling here? Most of the error string reporting will come from the custom types in the norad lib and we simply spit out the file path involved and the error message from the library error.

madig commented 3 years ago

You could make an error type that is basically

enum Error {
    UfoError(norad::Error),
    MyFormattingError(something),
    // ...
}

The Display trait could then just pass through whatever the norad error does.

chrissimpkins commented 3 years ago

You could make an error type that is basically


enum Error {

    UfoError(norad::Error),

    MyFormattingError(something),

    // ...

}

The Display trait could then just pass through whatever the norad error does.

I like it! Do you want to add this?

madig commented 3 years ago

One day. Maybe I'll use https://github.com/dtolnay/anyhow instead.

chrissimpkins commented 3 years ago

23