Skip to content

[bug] Risor Eval returns both result and non-nil error for error/function types #97

@robbyt

Description

@robbyt

Summary

engines/risor/evaluator/evaluator.go:148-153:

switch result.Object.Type() {
case "error":
    return result, fmt.Errorf("error returned from script: %s", result.Inspect())
case "function":
    return result, fmt.Errorf("function object returned from script: %s", result.Inspect())
}

When a Risor script returns a function or an error object, the evaluator returns both a non-nil EvaluatorResponse and a non-nil error. Most idiomatic Go callers will check err != nil first and discard the result without ever inspecting it — defeating the point of returning the result.

Open questions

  • Should returning a function be an error at all? If a script intentionally returns a callable, that's not necessarily a problem — Starlark (engines/starlark/evaluator/evaluator.go:201-210) handles it by calling the function with no args and returning that value. We could mirror that behavior, or make it an explicit choice.
  • Should the "error" case mirror Starlark's "freeze and return" behavior, or is the script's error value the script's idiomatic way to signal failure to the host?

Proposal

Pick one consistent contract across all engines, document it, and adjust this code to match. Probably either return (result, nil) always, or return (nil, err) always — never both.

Files

  • engines/risor/evaluator/evaluator.go:148-153
  • engines/starlark/evaluator/evaluator.go:201-210 (compare for consistency)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions