Skip to main content

qubit_clock/error/
tokio_runtime_error.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Defines errors caused by an unavailable ambient Tokio runtime.
9
10use thiserror::Error;
11use tokio::runtime::TryCurrentError;
12
13/// Describes why a Tokio-backed type cannot capture the current runtime.
14///
15/// This error occurs only in `try_current` constructors. Once constructed, a
16/// Tokio clock or timer uses its retained runtime handle and does not depend on
17/// the caller's ambient runtime context. The enum is non-exhaustive; callers
18/// must retain a fallback arm when matching it.
19#[non_exhaustive]
20#[derive(Debug, Error)]
21pub enum TokioRuntimeError {
22    /// No Tokio runtime is entered on the current thread.
23    #[error("no Tokio runtime is entered: {source}")]
24    NotEntered {
25        /// Runtime lookup error reported by Tokio.
26        #[source]
27        source: TryCurrentError,
28    },
29}