leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
16.17k stars 636 forks source link

`ServerFnError<T>` should impl `From<E: std::error::Error>` for any `T` #3153

Open nicolas-guichard opened 5 hours ago

nicolas-guichard commented 5 hours ago

Currently, ServerFnError has a blanket From impl to convert from E, but only with the default NoCustomError type:

impl<E: std::error::Error> From<E> for ServerFnError {
    fn from(value: E) -> Self {
        ServerFnError::ServerError(value.to_string())
    }
}

This means we can't easily use ? to convert other errors into a ServerFnError<MyCustomError>.

Instead I think we should provide a blanket impl for any T:

impl<T, E: std::error::Error> From<E> for ServerFnError<T> {
    fn from(value: E) -> Self {
        ServerFnError::ServerError(value.to_string())
    }
}
gbj commented 3 hours ago

Feel free to make a PR.