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
use std::convert::Infallible;
use crate::ValueType;
use thiserror::Error;
/// This type is used for all errors that can be returned by Polyvalue
#[derive(Error, Debug, Clone)]
pub enum Error {
/// An error caused by attempting to use a value of the wrong type in a calculation
#[error("Cannot perform {operation} on {actual_type}")]
UnsupportedOperation {
/// Operation that caused the error
operation: String,
/// Type that caused the error
actual_type: ValueType,
},
/// An error caused by attempting to convert a value to a different type
#[error("{src_type} cannot be converted to {dst_type}")]
ValueConversion {
/// Source type that caused the error
src_type: ValueType,
/// Destination type that caused the error
dst_type: ValueType,
},
/// An error caused by attempting to convert a value to a different type
#[error("Cannot expand a range of size {length}")]
RangeTooLarge {
/// Length of the range causing the issue
length: usize,
},
/// An error caused by attempting to use a value of the wrong type in a calculation
#[error("Expected {expected_type}, found {actual_type}")]
ValueType {
/// Type that caused the error
actual_type: ValueType,
/// Expected type that caused the error
expected_type: ValueType,
},
/// An error caused by attempting to use an invalid object or array key
#[error("Undefined index {key}")]
Index {
/// Index that caused the error
key: String,
},
/// An error caused by attempting to use an type as an object key
#[error("Type {0} cannot be used as an object key")]
InvalidTypeForKey(ValueType),
/// An error caused by attempting to use an invalid regex flag
#[error("Invalid regex flag {0}")]
InvalidRegexFlag(String),
/// An error caused by attempting to use an unsupported type
#[error("Unrecognized type {0}. Expected one of [array, bool, currency, fixed, float, int, object, string, numeric, collection, any]")]
UnrecognizedType(String),
/// An error caused by a calculation that resulted in an overflow
#[error("Arithmetic overflow")]
Overflow,
/// An error caused by parsing a value from a string
#[error("Invalid fixed-point literal")]
ParseDecimalError(#[from] fpdec::ParseDecimalError),
/// An error caused by parsing a value from a string
#[error("Invalid floatint-point literal")]
ParseFloatError(#[from] std::num::ParseFloatError),
/// An error caused by parsing a value from a string
#[error("Invalid integer literal")]
ParseIntError(#[from] std::num::ParseIntError),
/// An error caused by parsing a value from a string
#[error("Invalid range literal")]
InvalidRange,
/// An error caused by parsing a Decimal
#[error("Given value cannot be converted to Decimal")]
DecimalError(#[from] fpdec::DecimalError),
/// An error caused by parsing a regex
#[error("Invalid regex literal")]
RegexError(#[from] regex::Error),
/// An error caused by large allocations
#[error("Memory allocation error")]
TryReserveError(#[from] std::collections::TryReserveError),
}
impl From<Infallible> for Error {
fn from(x: Infallible) -> Self {
match x {}
}
}