grippo 0.2.3

Parse, match and scrub data faster and more efficiently.
Documentation
// Project:   grippo
// File:      src/expr/value.rs
// Purpose:   Why an expression's result is an error, and how a record miss reads in cel
// Language:  Rust
//
// License:   Apache-2.0
// Copyright: (c) 2026 HYPERI PTY LIMITED

//! cel's errors, and a [`Miss`] from a record read as the error cel raises.

use crate::record::Miss;

/// Why an expression's result is an error rather than true or false.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ErrorKind {
    /// A root field is absent, an undeclared variable in cel.
    MissingRoot,
    /// A key below the root is absent, or a step reads into a non-object.
    MissingField,
    /// An operator or method met a value of a type it doesn't take.
    TypeMismatch,
    /// The record is malformed where a field was read.
    Malformed,
    /// An int or uint sum, or an `int()` conversion, past its type's range.
    Overflow,
    /// `int()` met a string that isn't an int.
    Conversion,
}

/// The error cel raises for a field read that missed: a step into a
/// non-object is a missing field, as cel finds no key there.
pub(super) const fn read_error(miss: Miss) -> ErrorKind {
    match miss {
        Miss::MissingRoot => ErrorKind::MissingRoot,
        Miss::MissingField | Miss::WrongParentType => ErrorKind::MissingField,
        Miss::Malformed => ErrorKind::Malformed,
    }
}