Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

enum libtmux-rs latest

ScopeError

A scoped resource's creation, operation, or cleanup failure.

Source and package
Qualified name
libtmux::error::scoped::ScopeError
Module
error.scoped
Package
libtmux
Source
crates/libtmux/src/error/scoped.rs
enum error.scoped.ScopeError

Description#

Returned by crate::Server::with_session(), crate::Session::with_window(), and crate::Window::with_pane(). The operation error keeps its original type and value, with no From<Error> requirement. Cleanup failures retain Error::AfterEffect because creation succeeded; an operation error alone makes no replay guarantee. Self::Cleanup retains the operation's own result too: it already computed T when cleanup failed, and matching the variant is the only way to reach it, since the outer Result is Err either way.

Debug, Display, and std::error::Error are implemented for every T and E, but each only shows a value when its type supports it: Debug needs T: Debug and E: Debug, Display needs E: Display, and Error needs 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::source exposes the cleanup error in Self::Cleanup and Self::OperationAndCleanup, and the creation error in Self::Creation. It never exposes the operation error: E need not implement std::error::Error at all, so there is no &(dyn Error + 'static) to hand back even when Display can 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?;
Type parameters

Variants4#

ScopeError variants
CasePayloadDescription
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.
Esc

Type to search.

Reference previewOpen reference