Skip to main content

qubit_progress/error/
emission_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//! Errors while constructing or delivering non-start events.
9// qubit-style: allow source-test-pair
10
11use std::error::Error;
12use std::fmt;
13
14use crate::error::DeliveryError;
15
16/// Failure while emitting a Running or terminal event.
17#[derive(Clone, Debug)]
18#[non_exhaustive]
19pub enum EmissionError {
20    /// The operation's event sequence space is exhausted.
21    SequenceExhausted,
22    /// A reporter rejected one complete event.
23    Delivery(DeliveryError),
24}
25
26impl fmt::Display for EmissionError {
27    /// Formats the emission failure.
28    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            Self::SequenceExhausted => {
31                formatter.write_str("progress event sequence is exhausted")
32            }
33            Self::Delivery(error) => error.fmt(formatter),
34        }
35    }
36}
37
38impl Error for EmissionError {
39    /// Returns the nested delivery failure when present.
40    fn source(&self) -> Option<&(dyn Error + 'static)> {
41        match self {
42            Self::SequenceExhausted => None,
43            Self::Delivery(error) => Some(error),
44        }
45    }
46}