falco icon indicating copy to clipboard operation
falco copied to clipboard

[BUG] Error field of simulator output is an empty object

Open richardmarshall opened this issue 11 months ago • 0 comments

Kind of proposals

  • [x] Simulator

Describe the problem

When there is an interpreter error while handling a request in the simulator the error information is not properly marshaled to json.

VCL code that cause the problem / reproduceable

acl foo {}

sub vcl_recv {
  if ("aoeu" ~ foo) {
    esi;
  }
}
Request Incoming =========>
[RuntimeException] Left String type could not be a literal in main.vcl at line: 4, position: 14
<========= Request finished
% curl http://127.0.0.1:3124                                                                     
{
  "flows": [
    {
      "file": "main.vcl",
      "line": 3,
      "position": 1,
      "subroutine": "vcl_recv",
      "req": {
        "method": "GET",
        "url": "/",
        "headers": {
          "accept": "*/*",
          "host": "127.0.0.1:3124",
          "user-agent": "curl/8.4.0"
        }
      },
      "backend": ""
    }
  ],
  "logs": [],
  "restarts": 0,
  "backend": "",
  "cached": false,
  "elapsed_time_us": 119,
  "elapsed_time_ms": 0,
  "error": {}, <-- error field is just an empty object
  "client_response": {
    "status_code": 0,
    "body_bytes": 0,
    "headers": {},
    "body": ""
  }
}

Expected behavior

Error field in simulator output should contain the actual error message.

Cause

This is happening because the simulator output struct Error field is the type error. The go builtin error type does not implement json.Marshaler and does not have any public fields so the resulting json output is an empty object.

richardmarshall avatar Apr 03 '24 00:04 richardmarshall