1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//! 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>;