palantir / conjure-rust

Conjure support for Rust
Apache License 2.0
20 stars 11 forks source link

Creating conjure_error::Error from conjure generated error types #357

Closed rahij closed 3 months ago

rahij commented 3 months ago

What happened?

Creating an internal or service error currently has the following signature:

pub fn service<E, T>(cause: E, error_type: T) -> Error
    where
        E: Into<Box<dyn error::Error + Sync + Send>>,
        T: ErrorType + Serialize,
    {
    }

Errors defined in conjure generate objects which only implement ErrorType. Are users expected to create their own std::error::Error so that they can call this method?

sfackler commented 3 months ago

Yes, though many types implement Into<Box<dyn Error>>. For example, &'static str and String do, so you can do things like:

return Err(Error::service("you can't divide by 0", DivideByZeroError::new()));