Skip to content

Commit

Permalink
fix: Propagate errors encountered in argument evaluation (#308)
Browse files Browse the repository at this point in the history
fixes #301

Signed-off-by: Anand Krishnamoorthi <[email protected]>
  • Loading branch information
anakrish authored Aug 31, 2024
1 parent af50714 commit a4a80d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2283,15 +2283,8 @@ impl Interpreter {
};

let mut param_values = Vec::with_capacity(params.len());
let mut error = None;
for p in params {
match self.eval_expr(p) {
Ok(v) => param_values.push(v),
Err(e) => {
error = Some(Err(e));
break;
}
}
param_values.push(self.eval_expr(p)?);
}

let orig_fcn_path = fcn_path;
Expand All @@ -2308,9 +2301,6 @@ impl Interpreter {
if param_values.iter().any(|v| v == &Value::Undefined) {
return Ok(Value::Undefined);
}
if let Some(err) = error {
err?;
};
return Ok(v.clone());
}
_ => orig_fcn_path.clone(),
Expand Down
17 changes: 17 additions & 0 deletions tests/interpreter/cases/call/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,20 @@ cases:
a1 = inc(5)
query: data.test
want_result: {}

- note: call parameter raises error
data: {}
modules:
- |
package test
import rego.v1
bar := 1 if {
1 + "hello"
}
foo := 1 if {
count(bar)
}
query: data.test
error: expects numeric argument.

0 comments on commit a4a80d7

Please sign in to comment.