Add error for
This commit is contained in:
parent
820c863f7f
commit
699c37d860
@ -205,7 +205,11 @@ impl AbstractTree for ValueNode {
|
|||||||
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
||||||
let value = match self {
|
let value = match self {
|
||||||
ValueNode::Boolean(value_source) => Value::Boolean(value_source.parse().unwrap()),
|
ValueNode::Boolean(value_source) => Value::Boolean(value_source.parse().unwrap()),
|
||||||
ValueNode::Float(value_source) => Value::Float(value_source.parse().unwrap()),
|
ValueNode::Float(value_source) => {
|
||||||
|
let float = value_source.parse()?;
|
||||||
|
|
||||||
|
Value::Float(float)
|
||||||
|
}
|
||||||
ValueNode::Function(function) => Value::Function(function.clone()),
|
ValueNode::Function(function) => Value::Function(function.clone()),
|
||||||
ValueNode::Integer(value_source) => Value::Integer(value_source.parse().unwrap()),
|
ValueNode::Integer(value_source) => Value::Integer(value_source.parse().unwrap()),
|
||||||
ValueNode::String(value_source) => Value::string(value_source.clone()),
|
ValueNode::String(value_source) => Value::string(value_source.clone()),
|
||||||
|
12
src/error.rs
12
src/error.rs
@ -176,6 +176,11 @@ pub enum Error {
|
|||||||
SerdeJson(String),
|
SerdeJson(String),
|
||||||
|
|
||||||
ParserCancelled,
|
ParserCancelled,
|
||||||
|
|
||||||
|
ParseFloat {
|
||||||
|
reason: String,
|
||||||
|
},
|
||||||
|
|
||||||
ExpectedIterable {
|
ExpectedIterable {
|
||||||
actual: Value,
|
actual: Value,
|
||||||
},
|
},
|
||||||
@ -441,6 +446,13 @@ impl fmt::Display for Error {
|
|||||||
f,
|
f,
|
||||||
"Parsing was cancelled either manually or because it took too long."
|
"Parsing was cancelled either manually or because it took too long."
|
||||||
),
|
),
|
||||||
|
ParseFloat { reason } => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Failed to parse a float value. Reason given: {}.",
|
||||||
|
reason
|
||||||
|
)
|
||||||
|
}
|
||||||
ExpectedFunctionType { actual } => write!(f, "Expected a function but got {actual}."),
|
ExpectedFunctionType { actual } => write!(f, "Expected a function but got {actual}."),
|
||||||
ExpectedIterable { actual } => {
|
ExpectedIterable { actual } => {
|
||||||
write!(f, "Expected an iterable value but got {actual}.")
|
write!(f, "Expected an iterable value but got {actual}.")
|
||||||
|
Loading…
Reference in New Issue
Block a user