-
-
Notifications
You must be signed in to change notification settings - Fork 655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoCustomError
should be replaced by Infallible
(or another empty enum
)
#3154
Comments
If/when this is implemented, we could provide an infallible conversion from impl<CustErr> From<ServerFnError<NoCustomError>> for ServerFnError<CustErr> {
fn from(value: ServerFnError<NoCustomError>) -> Self {
match self {
// not needed since Rust 1.82 if NoCustomError becomes uninhabited:
// ServerFnError::<NoCustomError>::WrappedServerError(_) => unreachable!(),
ServerFnError::<NoCustomError>::Registration(s) => ServerFnError::<CustErr>::Registration(s),
ServerFnError::<NoCustomError>::Request(s) => ServerFnError::<CustErr>::Request(s),
ServerFnError::<NoCustomError>::Response(s) => ServerFnError::<CustErr>::Response(s),
ServerFnError::<NoCustomError>::ServerError(s) => ServerFnError::<CustErr>::ServerError(s),
ServerFnError::<NoCustomError>::Deserialization(s) => ServerFnError::<CustErr>::Deserialization(s),
ServerFnError::<NoCustomError>::Serialization(s) => ServerFnError::<CustErr>::Serialization(s),
ServerFnError::<NoCustomError>::Args(s) => ServerFnError::<CustErr>::Args(s),
ServerFnError::<NoCustomError>::MissingArg(s) => ServerFnError::<CustErr>::MissingArg(s),
}
}
} Currently to enable the |
Could you provide an example of the problem you're trying to solve? |
For instance let's say I have a helper function like this: pub fn auth() -> Result<AuthSession, ServerFnError> {
use_context::<AuthSession>().ok_or_else(|| {
ServerFnError::ServerError("Auth session missing.".into())
})
} I want to write this: enum GetUsernameError {
NotLoggedIn,
}
#[server]
pub async fn get_username() -> Result<Option<User>, ServerFnError<GetUsernameError>> {
use crate::todo::ssr::auth;
let auth = auth()?; // ← this currently fails, adding the From impl above solves that, and making NoCustomError uninhabited makes it infallible
match auth.current_user {
None => Err(GetUsernameError::NotLoggedIn.into()),
Some(user) => Ok(user.name),
}
} If you don't have anything against those additions, I'll send PRs your way. |
Sure. Can't say I understand this one, but I have never used the custom errors so I am sure I will once I see a PR! |
I understand this one, but expect it's not possible for us. If we replaced NoCustomError, which is an empty struct, with Infallible, we wouldn't be able to derive the traits we need for the orphan rule. I'm going to close this, but if you can prove me wrong with a PR, that'd be great |
Contrary to an empty struct, which has exactly 1 possible value, an empty enum has 0 possible values: it can't even be constructed. Fixes leptos-rs#3154
Contrary to an empty struct, which has exactly 1 possible value, an empty enum has 0 possible values: it can't even be constructed. Fixes leptos-rs#3154
When matching over a
ServerFnError
, we always have to cover theWrappedServerError
case, even though it should not be used whenCustErr = NoCustomError
.This happens because
NoCustomError
is an emptystruct
, which can be constructed.Instead I think we should use an empty
enum
such asstd::convert::Infallible
, which would:This would however be a breaking change.
The text was updated successfully, but these errors were encountered: