expressive/src/error/mod.rs

96 lines
3.7 KiB
Rust
Raw Normal View History

2016-11-16 16:12:26 +00:00
use serde_json::Value;
use operator::Operator;
quick_error! {
/// Expression parsing error
2016-11-16 16:12:26 +00:00
#[derive(Debug, PartialEq)]
pub enum Error {
/// Unsupported operator yet.
2016-11-16 16:12:26 +00:00
UnsupportedOperator(operator: String) {
display("Unsupported operator: {:?}", operator)
}
/// This operator does not support execution.
2016-11-16 16:12:26 +00:00
CanNotExec(operator: Operator) {
display("This operator does not support execution: {:?}", operator)
}
/// Your expression may start with non-value operator like ( + * )
2016-11-16 16:12:26 +00:00
StartWithNonValueOperator {
display("Your expression may start with non-value operator like ( + * ).")
}
/// Unpaired brackets, left brackets count does not equal right brackets count
2016-11-16 16:12:26 +00:00
UnpairedBrackets {
display("Unpaired brackets, left brackets count does not equal right brackets count.")
}
/// Duplicate values node, you may have (2 3) but there is no operators between them
2016-11-16 16:12:26 +00:00
DuplicateValueNode {
display("Duplicate values node, you may have (2 3) but there is no operators between them.")
}
/// Duplicate operators node, you may have (+ +) but there is no values between them
2016-11-16 16:12:26 +00:00
DuplicateOperatorNode {
display("Duplicate operators node, you may have (+ +) but there is no values between them.")
}
/// You have a comma(,) , but there is no function in front of it.
2016-11-16 16:12:26 +00:00
CommaNotWithFunction {
display("You have a comma(,) , but there is no function in front of it.")
}
/// You have empty brackets () , but there is no function in front of it.
2016-11-16 16:12:26 +00:00
BracketNotWithFunction {
display("You have empty brackets () , but there is no function in front of it.")
}
/// Function not exists.
2016-11-16 16:12:26 +00:00
FunctionNotExists(ident: String) {
display("Function not exists: {}", ident)
}
/// Expected a boolean but the given value isn't.
2016-11-21 01:14:40 +00:00
ExpectedBoolean(value: Value) {
display("Expected a boolean, found: {}", value)
2016-11-16 16:12:26 +00:00
}
/// Expected ident.
2016-11-21 01:14:40 +00:00
ExpectedIdentifier {
display("Expected ident.")
}
/// Expected array.
2016-11-21 01:14:40 +00:00
ExpectedArray {
display("Expected array.")
}
/// Expected object.
2016-11-21 01:14:40 +00:00
ExpectedObject {
display("Expected object.")
}
/// Expect number.
2016-11-21 01:14:40 +00:00
ExpectedNumber {
display("Expected number.")
}
/// Failed to parse, no final expression.
2016-11-16 16:12:26 +00:00
NoFinalNode {
display("Failed to parse, no final expression.")
}
/// The number of arguments is greater than the maximum limit.
2016-11-16 16:12:26 +00:00
ArgumentsGreater(max: usize) {
display("The number of arguments is greater than the maximum limit: {}", max)
}
/// The number of arguments is less than the minimum limit.
2016-11-16 16:12:26 +00:00
ArgumentsLess(min: usize) {
display("The number of arguments is less than the minimum limit: {}", min)
}
/// This two value types are different or do not support mathematical calculations.
2016-11-16 16:12:26 +00:00
UnsupportedTypes(a: String, b: String) {
display("This two value types are different or do not support mathematical calculations: {}, {}", a, b)
}
/// Invalid range expression like `1..2..3`
2016-11-16 16:28:54 +00:00
InvalidRange(ident: String) {
display("Invalid range expression: {}", ident)
2016-11-16 16:12:26 +00:00
}
/// Can not add child node.
2016-11-21 01:14:40 +00:00
CanNotAddChild {
display("Can not add child node.")
}
/// Custom error.
2016-11-16 16:12:26 +00:00
Custom(detail: String) {
display("{}", detail)
}
}
}