Repository: microsoft/regorus (language: python)

Issue:
Do not raise errors from builtins in when evaluation is not strict.
Currently regorus will raise errors from builtin functions even when not executing in strict mode. To be compatible with OPA, beyond the OPA testsuite, we need to change to behavior to not raise errors from builtins when not in strict mode. Instead of errors, Undefined will be propagated to the caller.


Discussion / hints:

Fix patch:
diff --git a/src/interpreter.rs b/src/interpreter.rs
index fce242da..88cc5599 100644
--- a/src/interpreter.rs
+++ b/src/interpreter.rs
@@ -2055,7 +2055,12 @@ impl Interpreter {
             }
         }
 
-        let v = builtin.0(span, params, &args[..], self.strict_builtin_errors)?;
+        let v = match builtin.0(span, params, &args[..], self.strict_builtin_errors) {
+            Ok(v) => v,
+            // Ignore errors if we are not evaluating in strict mode.
+            Err(_) if !self.strict_builtin_errors => return Ok(Value::Undefined),
+            Err(e) => Err(e)?,
+        };
 
         // Handle trace function.
         // TODO: with modifier.


Test patch:
diff --git a/tests/interpreter/cases/nonstrict/tests.yaml b/tests/interpreter/cases/nonstrict/tests.yaml
new file mode 100644
index 00000000..665ff134
--- /dev/null
+++ b/tests/interpreter/cases/nonstrict/tests.yaml
@@ -0,0 +1,19 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+  cases:
+    - note: builtin error gobbled up in non strict mode
+      modules:
+        - |
+          package test
+          a = to_number("abc")
+      query: data.test
+      want_result: {}
+      strict: false
+
+    - note: builtin error in strict mode
+      modules:
+        - |
+          package test
+          a = to_number("abc")
+      query: data.test
+      error: "could not parse string as number"