DioxusLabs / DioxusLabs/dioxus

Provide Error in handle_error closure instead of Option<Error>

Open
#4,743 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

## Feature Request

The new version of the error boundary only provides access to Option in the error boundary, but the option should always be some. For almost all cases, you will need to unwrap the option to get the inner error when you handle the error

```rust
// [package]
// name = "dx-rc07"
// version = "0.1.0"
// edition = "2024"

// [dependencies]
// dioxus = { version = "0.7.0-rc.1", features = ["web"] }
use dioxus::prelude::*;

fn App() -> Element {
let mut multiplier = use_signal(|| String::from("2"));
rsx! {
input {
r#type: "text",
value: multiplier,
oninput: move |e| multiplier.set(e.value())
}
ErrorBoundary {
handle_error: |errors: ErrorContext| {
rsx! {
// This should always be Some inside of the handle_error closure?
if let Some(error) = errors.error() {
div {
"Oops, we encountered an error. Please report {error} to the developer of this application"
}
}
}
},
Counter {
multiplier
}
}
}
}

#[component]
fn Counter(multiplier: ReadSignal) -> Element {
let multiplier_parsed = multiplier().parse::()?;
let mut count = use_signal(|| multiplier_parsed);
rsx! {
button {
onclick: move |_| {
let multiplier_parsed = multiplier().parse::()?;
*count.write() *= multiplier_parsed;
Ok(())
},
"{count}x{multiplier}"
}
}
}

fn main() {
dioxus::launch(App);
}
```

## Implement Suggestion

We should provide the error itself as part of the closure arguments either as the only argument (and you can consume the context if you need it) or through a wrapper on top of the error context

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.