Skip to content

Commit

Permalink
Add beginner tip to ErrorBoundary (#2385)
Browse files Browse the repository at this point in the history
* Add beginner tip to ErrorBoundary

This might seem simple, but the nuances of types and traits confuse many people learning the language.

* edit

* Update error_boundary.rs

* edits

* ignore error block
  • Loading branch information
sjud authored Apr 14, 2024
1 parent 1ff0a71 commit 35a8ca1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions leptos/src/error_boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ use leptos_reactive::{provide_context, run_as_child, signal_prelude::*};
/// {move || {
/// /* etc. */
/// ```
///
/// ## Beginner's Tip: ErrorBoundary Requires Your Error To Implement std::error::Error.
/// `ErrorBoundary` requires your `Result<T,E>` to implement [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html).
/// `Result<T,E>` only implements `IntoView` if `E` implements [std::error::Error](https://doc.rust-lang.org/std/error/trait.Error.html).
/// So, for instance, if you pass a `Result<T,String>` where `T` implements [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html)
/// and attempt to render the error for the purposes of `ErrorBoundary` you'll get a compiler error like this.
///
/// ```rust,ignore
/// error[E0599]: the method `into_view` exists for enum `Result<ViewableLoginFlow, String>`, but its trait bounds were not satisfied
/// --> src/login.rs:229:32
/// |
/// 229 | err => err.into_view(),
/// | ^^^^^^^^^ method cannot be called on `Result<ViewableLoginFlow, String>` due to unsatisfied trait bounds
/// |
/// = note: the following trait bounds were not satisfied:
/// `<&Result<ViewableLoginFlow, std::string::String> as FnOnce<()>>::Output = _`
/// which is required by `&Result<ViewableLoginFlow, std::string::String>: leptos::IntoView`
/// ... more notes here ...
/// ```
///
/// For more information about how to easily implement `Error` see
/// [thiserror](https://docs.rs/thiserror/latest/thiserror/)
#[component]
pub fn ErrorBoundary<F, IV>(
/// The components inside the tag which will get rendered
Expand Down

0 comments on commit 35a8ca1

Please sign in to comment.