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