1
0

Add error for

This commit is contained in:
Jeff 2024-01-31 12:17:13 -05:00
parent 820c863f7f
commit 699c37d860
2 changed files with 17 additions and 1 deletions

View File

@ -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()),

View File

@ -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}.")