Repository: clarkmcc/cel-rust (language: rust)

Issue:
Unresolved method/function calls panic
Could be a regression because of #59 - though looks like the `unwrap()` on the lookup was there before.
Anyways, what led me to start working on #64 is hitting that very problem invoking `bytes()`:

```
panicked at interpreter/src/objects.rs:526:58:
called `Option::unwrap()` on a `None` value
```

Unsure what error should be reported, but panicking isn't certainly not the right thing. I'll look into it


Discussion / hints:
I apologize, I'm not sure I totally follow. Is this a new issue introduced by #64? I see that PR introduces an `.unwrap()` call that wasn't there before, but maybe that's not the unwrap that you're referring to? Can you clarify what the problem is and what expression could reproduce it? I'm happy to investigate as well.
Yeah, sorry this was probably not real clear. So, yes… when calling to a function that doesn't exists (e.g. `bytes("abc")`), the `Option.unwrap` panics [here](https://github.com/clarkmcc/cel-rust/blob/master/interpreter/src/objects.rs#L526), that `.unwrap()` was already [there tho](https://github.com/clarkmcc/cel-rust/pull/59/files#diff-83ad9b099e2007a60850d83e047c7b864b2015e633d0a16e6ef5058130d1f6fbL599). I don't know, though I don't think so, that something else made sure the function existed _prior_ that call before the refactoring… 
I guess the question becomes, what should the behavior be? `UndeclaredReference` based on [the description there](https://github.com/clarkmcc/cel-rust/blob/be772a5f8d1080ef8badc6754f94ecd57ac1cfb2/interpreter/src/lib.rs#L54-L57), correct? 

Fix patch:
diff --git a/interpreter/src/context.rs b/interpreter/src/context.rs
index 0b21f67..c19037f 100644
--- a/interpreter/src/context.rs
+++ b/interpreter/src/context.rs
@@ -85,11 +85,11 @@ impl<'a> Context<'a> {
                 .get(&name)
                 .cloned()
                 .or_else(|| parent.get_variable(&name).ok())
-                .ok_or(ExecutionError::UndeclaredReference(name.into())),
+                .ok_or_else(|| ExecutionError::UndeclaredReference(name.into())),
             Context::Root { variables, .. } => variables
                 .get(&name)
                 .cloned()
-                .ok_or(ExecutionError::UndeclaredReference(name.into())),
+                .ok_or_else(|| ExecutionError::UndeclaredReference(name.into())),
         }
     }
 
diff --git a/interpreter/src/lib.rs b/interpreter/src/lib.rs
index 77ffe6d..bd28d47 100644
--- a/interpreter/src/lib.rs
+++ b/interpreter/src/lib.rs
@@ -262,6 +262,16 @@ mod tests {
                 "missing == 1",
                 ExecutionError::undeclared_reference("missing"),
             ),
+            (
+                "undeclared method",
+                "1.missing()",
+                ExecutionError::undeclared_reference("missing"),
+            ),
+            (
+                "undeclared function",
+                "missing(1)",
+                ExecutionError::undeclared_reference("missing"),
+            ),
             (
                 "unsupported key type",
                 "{null: true}",
diff --git a/interpreter/src/objects.rs b/interpreter/src/objects.rs
index 58bd6ce..46ebeac 100644
--- a/interpreter/src/objects.rs
+++ b/interpreter/src/objects.rs
@@ -523,7 +523,9 @@ impl<'a> Value {
             Expression::Ident(name) => ctx.get_variable(&***name),
             Expression::FunctionCall(name, target, args) => {
                 if let Expression::Ident(name) = &**name {
-                    let func = ctx.get_function(&**name).unwrap();
+                    let func = ctx
+                        .get_function(&**name)
+                        .ok_or_else(|| ExecutionError::UndeclaredReference(Arc::clone(name)))?;
                     match target {
                         None => {
                             let mut ctx =


Test patch: