qubit-validator 0.1.0

Type-safe validation traits and registries for Qubit applications
Documentation
// =============================================================================
//    Copyright (c) 2025 - 2026 Haixing Hu.
//
//    SPDX-License-Identifier: Apache-2.0
//
//    Licensed under the Apache License, Version 2.0.
// =============================================================================

//! Execution error kinds.

use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result;

/// A failure in the validation execution infrastructure.
///
/// # Examples
///
/// ```
/// use qubit_validator::ExecutionErrorKind;
///
/// let kind = ExecutionErrorKind::InputTypeMismatch;
/// assert_eq!(kind.to_string(), "input type mismatch");
/// ```
#[must_use]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ExecutionErrorKind {
    /// The supplied input has the wrong erased type.
    InputTypeMismatch,
    /// The validation selection contains no matching validation path.
    InvalidSelection,
    /// A dependency has the wrong erased type.
    DependencyTypeMismatch,
    /// A required dependency value is absent.
    MissingRequiredDependencyValue,
    /// A named dependency value is supplied more than once.
    DuplicateDependencyBinding,
    /// A named dependency does not exist in the selected signature.
    UnknownDependencyBinding,
    /// A declared dependency value was not supplied by name.
    MissingDependencyBinding,
    /// A property could not be read.
    PropertyReadFailed,
    /// Traversal exceeded an execution budget.
    TraversalLimit,
    /// A prepared adapter returned an invalid protocol result.
    AdapterContractViolation,
    /// An external operation failed.
    ExternalFailure,
}

impl Display for ExecutionErrorKind {
    /// Formats the stable human-readable error category.
    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
        let name = match self {
            Self::InputTypeMismatch => "input type mismatch",
            Self::InvalidSelection => "invalid validation selection",
            Self::DependencyTypeMismatch => "dependency type mismatch",
            Self::MissingRequiredDependencyValue => "missing required dependency value",
            Self::DuplicateDependencyBinding => "duplicate dependency binding",
            Self::UnknownDependencyBinding => "unknown dependency binding",
            Self::MissingDependencyBinding => "missing dependency binding",
            Self::PropertyReadFailed => "property read failed",
            Self::TraversalLimit => "traversal limit exceeded",
            Self::AdapterContractViolation => "adapter contract violation",
            Self::ExternalFailure => "external failure",
        };
        formatter.write_str(name)
    }
}