graphddb_runtime 0.7.6

Rust runtime for GraphDDB — interprets the language-neutral IR (manifest.json + operations.json) and executes the validated access patterns against DynamoDB.
Documentation
//! Error taxonomy for the GraphDDB Rust runtime (issue #214).
//!
//! Mirrors `python/graphddb_runtime/errors.py` via `thiserror`. Every
//! runtime-raised error is a [`GraphDDBError`] variant so a caller can match the
//! whole family; the [`GraphDDBError::kind`] carries the specific class (parity
//! with the Python subclass hierarchy `QueryNotFoundError`,
//! `ParameterValidationError`, …).

use thiserror::Error;

/// The specific error class, mirroring the Python `GraphDDBError` subclasses.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorKind {
    /// Base / uncategorized runtime error.
    Generic,
    /// An `execute_query` was given an unknown query id.
    QueryNotFound,
    /// An `execute_command` was given an unknown command id.
    CommandNotFound,
    /// An `execute_transaction` was given an unknown transaction id.
    TransactionNotFound,
    /// An unknown contract / method, or a method whose kind does not match.
    ContractNotFound,
    /// A contract method called with the wrong input arity (array into `single`).
    ContractArity,
    /// Params failed validation before any DynamoDB call.
    ParameterValidation,
    /// A runtime limit would be exceeded before any DynamoDB call.
    LimitExceeded,
    /// A DynamoDB call failed (wraps the SDK error message).
    OperationExecution,
    /// A raw DynamoDB item could not be hydrated.
    Hydration,
    /// A query/command needs more than the single-op core (out of scope path).
    MultiOperationNotSupported,
}

/// The single error type for the runtime. `kind` distinguishes the class; the
/// message mirrors the Python messages closely.
#[derive(Debug, Error, Clone)]
#[error("{message}")]
pub struct GraphDDBError {
    /// The specific error class.
    pub kind: ErrorKind,
    /// The human-readable message.
    pub message: String,
}

impl GraphDDBError {
    /// A generic runtime error with `message`.
    pub fn new(message: impl Into<String>) -> Self {
        Self {
            kind: ErrorKind::Generic,
            message: message.into(),
        }
    }

    /// An error of a specific `kind`.
    pub fn of(kind: ErrorKind, message: impl Into<String>) -> Self {
        Self {
            kind,
            message: message.into(),
        }
    }

    /// `QueryNotFoundError` counterpart.
    pub fn query_not_found(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::QueryNotFound, message)
    }
    /// `CommandNotFoundError` counterpart.
    pub fn command_not_found(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::CommandNotFound, message)
    }
    /// `TransactionNotFoundError` counterpart.
    pub fn transaction_not_found(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::TransactionNotFound, message)
    }
    /// `ContractNotFoundError` counterpart.
    pub fn contract_not_found(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::ContractNotFound, message)
    }
    /// `ContractArityError` counterpart.
    pub fn contract_arity(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::ContractArity, message)
    }
    /// `ParameterValidationError` counterpart.
    pub fn parameter_validation(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::ParameterValidation, message)
    }
    /// `LimitExceededError` counterpart.
    pub fn limit_exceeded(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::LimitExceeded, message)
    }
    /// `OperationExecutionError` counterpart (wraps an SDK failure).
    pub fn operation_execution(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::OperationExecution, message)
    }
    /// `HydrationError` counterpart.
    pub fn hydration(message: impl Into<String>) -> Self {
        Self::of(ErrorKind::Hydration, message)
    }
}

/// The runtime result alias.
pub type Result<T> = std::result::Result<T, GraphDDBError>;