DioxusLabs/dioxus · error
Tried to access `ok` on an Err value
Error message
Tried to access `ok` on an Err value
What it means
`Store<Result<T,E>>::ok()` returns None when the store currently holds an Err value. The message surfaces if a store that must be Ok at this point is Err — i.e. the tracked Result state changed to (or was created as) Err while calling code assumed success. The docstring documents this shallow-tracking semantics; the panic text is the diagnostic shown when code unwraps through the Err branch.
Source
Thrown at packages/stores/src/impls/result.rs:96
}
/// Converts `Store<Result<T, E>>` into `Option<Store<T>>`, discarding the error if present. This will
/// only track the shallow state of the `Result`. It will only cause a re-run if the `Result` could
/// change from `Err` to `Ok` or vice versa.
///
/// # Example
/// ```rust, no_run
/// use dioxus_stores::*;
/// let store = use_store(|| Ok::<u32, ()>(42));
/// match store.ok() {
/// Some(ok_store) => assert_eq!(ok_store(), 42),
/// None => panic!("Expected Ok"),
/// }
/// ```
pub fn ok(self) -> Option<MappedStore<T, Lens>> {
let map: fn(&Result<T, E>) -> &T = |value| {
value.as_ref().unwrap_or_else(|_| {
panic!("Tried to access `ok` on an Err value");
})
};
let map_mut: fn(&mut Result<T, E>) -> &mut T = |value| {
value.as_mut().unwrap_or_else(|_| {
panic!("Tried to access `ok` on an Err value");
})
};
self.is_ok()
.then(|| self.into_selector().child(0, map, map_mut).into())
}
/// Converts `Store<Result<T, E>>` into `Option<Store<E>>`, discarding the success if present. This will
/// only track the shallow state of the `Result`. It will only cause a re-run if the `Result` could
/// change from `Ok` to `Err` or vice versa.
///
/// # Example
/// ```rust, no_run
/// use dioxus_stores::*;View on GitHub (pinned to 24f6a829df)
Solutions
- The Result value is Err. Match on the Result before accessing the ok payload.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at packages/stores/src/impls/result.rs:96 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23).
Data as JSON: /api/errors/47822e0fdc67deb9.
Report an issue: GitHub.