ScopeError
A scoped resource's creation, operation, or cleanup failure.
Source and package
- Qualified name
-
libtmux::error:: scoped:: Scope Error - Module
- error.scoped
- Package
- libtmux
- Source
- crates/libtmux/src/error/scoped.rs
-
Description#
Returned by
crate::Server::with_session(),crate::Session::with_window(), andcrate::Window::with_pane(). The operation error keeps its original type and value, with noFrom<Error>requirement. Cleanup failures retainError::AfterEffectbecause creation succeeded; an operation error alone makes no replay guarantee.Self::Cleanupretains the operation's own result too: it already computedTwhen cleanup failed, and matching the variant is the only way to reach it, since the outerResultisErreither way.Debug,Display, andstd::error::Errorare implemented for everyTandE, but each only shows a value when its type supports it:DebugneedsT: DebugandE: Debug,DisplayneedsE: Display, andErrorneeds both, since it requires them as supertraits. A caller whose types have neither still gets a working scope: both values remain reachable by matching the variant, and creation and cleanup failures format and chain regardless.std::error::Error::sourceexposes the cleanup error inSelf::CleanupandSelf::OperationAndCleanup, and the creation error inSelf::Creation. It never exposes the operation error:Eneed not implementstd::error::Errorat all, so there is no&(dyn Error + 'static)to hand back even whenDisplaycan show it. Match the variant to reach it directly.Examples#
use libtmux::ScopeError;let guard = libtmux::test::TestServer::new().await?;let outcome = guard.server().with_session("work", async |_session| {Err::<(), _>("operation failed")}).await;assert!(matches!(outcome, Err(ScopeError::Operation("operation failed"))));guard.shutdown().await?;
Variants4#
| Case | Payload | Description |
|---|---|---|
| Cleanup | { value: T, cleanup: Error } | The operation succeeded, but cleanup failed after creation. |
| Creation | (Error) | The resource could not be created; the operation did not run. |
| Operation | (E) | The operation failed and cleanup succeeded. |
| OperationAndCleanup | { operation: E, cleanup: Error } | The operation and cleanup both failed. |
Members3#
- into_operation method Take the operation's own error, when the operation is what failed.
- into_value method Take the value the operation produced before cleanup failed.
- tmux_error method Borrow the tmux error from creation or cleanup.