Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SessionClosed error #1487

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl SessionState {
self.primitives
.as_ref()
.cloned()
.ok_or_else(|| zerror!("session closed").into())
.ok_or_else(|| SessionClosedError.into())
}

#[inline]
Expand Down Expand Up @@ -516,6 +516,21 @@ impl Drop for WeakSession {
}
}

/// Error indicating the operation cannot proceed because the session is closed.
///
/// It may be returned by operations like [`Session::get`] or [`Publisher::put`] when
/// [`Session::close`] has been called before.
#[derive(Debug)]
pub struct SessionClosedError;

impl fmt::Display for SessionClosedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "session closed")
}
}

impl std::error::Error for SessionClosedError {}

static SESSION_ID_COUNTER: AtomicU16 = AtomicU16::new(0);
impl Session {
pub(crate) fn init(
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub mod session {
builders::publisher::{SessionDeleteBuilder, SessionPutBuilder},
info::{PeersZenohIdBuilder, RoutersZenohIdBuilder, SessionInfo, ZenohIdBuilder},
query::SessionGetBuilder,
session::{open, OpenBuilder, Session, Undeclarable},
session::{open, OpenBuilder, Session, SessionClosedError, Undeclarable},
};
}

Expand Down
Loading