Skip to main content

qubit_validator/binding/
execution_error_kind.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
9//! Execution error kinds.
10
11use std::fmt::Display;
12use std::fmt::Formatter;
13use std::fmt::Result;
14
15/// A failure in the validation execution infrastructure.
16///
17/// # Examples
18///
19/// ```
20/// use qubit_validator::ExecutionErrorKind;
21///
22/// let kind = ExecutionErrorKind::InputTypeMismatch;
23/// assert_eq!(kind.to_string(), "input type mismatch");
24/// ```
25#[must_use]
26#[derive(Clone, Copy, Debug, Eq, PartialEq)]
27#[non_exhaustive]
28pub enum ExecutionErrorKind {
29    /// The supplied input has the wrong erased type.
30    InputTypeMismatch,
31    /// The validation selection contains no matching validation path.
32    InvalidSelection,
33    /// A dependency has the wrong erased type.
34    DependencyTypeMismatch,
35    /// A required dependency value is absent.
36    MissingRequiredDependencyValue,
37    /// A named dependency value is supplied more than once.
38    DuplicateDependencyBinding,
39    /// A named dependency does not exist in the selected signature.
40    UnknownDependencyBinding,
41    /// A declared dependency value was not supplied by name.
42    MissingDependencyBinding,
43    /// A property could not be read.
44    PropertyReadFailed,
45    /// Traversal exceeded an execution budget.
46    TraversalLimit,
47    /// A prepared adapter returned an invalid protocol result.
48    AdapterContractViolation,
49    /// An external operation failed.
50    ExternalFailure,
51}
52
53impl Display for ExecutionErrorKind {
54    /// Formats the stable human-readable error category.
55    ///
56    /// # Parameters
57    ///
58    /// - `formatter`: Receives the category's stable human-readable text.
59    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
60        let name = match self {
61            Self::InputTypeMismatch => "input type mismatch",
62            Self::InvalidSelection => "invalid validation selection",
63            Self::DependencyTypeMismatch => "dependency type mismatch",
64            Self::MissingRequiredDependencyValue => "missing required dependency value",
65            Self::DuplicateDependencyBinding => "duplicate dependency binding",
66            Self::UnknownDependencyBinding => "unknown dependency binding",
67            Self::MissingDependencyBinding => "missing dependency binding",
68            Self::PropertyReadFailed => "property read failed",
69            Self::TraversalLimit => "traversal limit exceeded",
70            Self::AdapterContractViolation => "adapter contract violation",
71            Self::ExternalFailure => "external failure",
72        };
73        formatter.write_str(name)
74    }
75}