arena_terms/
error.rs

1//! Defines [`TermError`], the unified error type for term operations.
2//!
3//! Provides descriptive error variants for invalid terms, epochs,
4//! kind or arity mismatches, and related arena issues.
5
6use crate::{EpochID, Slice, Term};
7use smartstring::alias::String;
8use thiserror::Error;
9
10/// Represents all possible errors that can occur within the calculator.
11///
12/// [`TermError`] provides a single error surface for higher-level functions.
13/// Each variant wraps a more specific underlying error, and thanks to `#[from]`
14/// you can write `?` at call sites without explicit mapping.
15///
16
17#[derive(Debug, Clone, Error)]
18pub enum TermError {
19    #[error("Invalid term {0:?}")]
20    InvalidTerm(Term),
21
22    #[error("Epoch overflow")]
23    LiveEpochsExceeded,
24
25    #[error("Invalid epoch {0:?}")]
26    InvalidEpoch(EpochID),
27
28    #[error("Missing functor")]
29    MissingFunctor,
30
31    #[error("Invalid functor {0:?}")]
32    InvalidFunctor(Term),
33
34    #[error("Type mismatch: expected {expected}, found {found}")]
35    UnexpectedKind {
36        expected: &'static str,
37        found: &'static str,
38    },
39
40    #[error("Arity mismatch: expected {expected}, found {found}")]
41    UnexpectedArity { expected: usize, found: usize },
42
43    #[error("Unexpected name in {0:?}")]
44    UnexpectedName(Term),
45
46    // OperDef fixity errors
47    #[error("invalid fixity: {0}")]
48    InvalidFixity(String),
49
50    // OperDef associativity errors
51    #[error("invalid associativity: {0}")]
52    InvalidAssoc(String),
53
54    // An   OperDef error
55    #[error("operdef error: {0}")]
56    OperDef(String),
57}
58
59/// Internal errors that may occur when constructing terms or
60/// interacting with arena.
61#[derive(Debug, Clone, Error)]
62pub(crate) enum InternalTermError {
63    /// Invalid arena epoch ID.
64    #[error("invalid arena epoch: {0:?}")]
65    InvalidEpoch(EpochID),
66
67    /// Invalid slice.
68    #[error("invalid term slice: {0:?}")]
69    InvalidSlice(Slice),
70}