Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty printed trace output should include location details #2070

Closed
patrick-east opened this issue Feb 7, 2020 · 0 comments · Fixed by #2079
Closed

Pretty printed trace output should include location details #2070

patrick-east opened this issue Feb 7, 2020 · 0 comments · Fixed by #2079

Comments

@patrick-east
Copy link
Contributor

Expected Behavior

The pretty printed trace output via --explain <level> --format pretty for some eval:

opa eval -d /tmp/x.rego --explain fails -f pretty 'data.x'
Enter data.x = _
| Enter data.x.p
| | Enter data.x.z
| | | Fail 1 = 2
| | Fail data.x.z
| Enter data.x.z
| | Fail 1 = 2

Doesn't include any of the location data to help link the trace events back to the source rego. The raw trace objects already have this data, and you can see it in the json format... but its not something that a person troubleshooting would want to go look at... ex:

"explanation": [
    {
      "Op": "Enter",
      "Node": [
        {
          "index": 0,
          "terms": [
            {
              "type": "ref",
              "value": [

<snip>

      },
      "Location": {
        "file": "./x.rego",
        "row": 4,
        "col": 3
      },
      "QueryID": 2,
      "ParentID": 0,
      "Locals": null,
      "LocalMetadata": {},
      "Message": ""
    }
  ]

What would be ideal is to surface some of the location data in the pretty trace output format.

Proposed change

Prefix the lines with the location information, for example with the trace shown above we could instead have something more like:

<query>:1    Enter data.x = _
x.rego:3     | Enter data.x.p
x.rego:7     | | Enter data.x.z
x.rego:8     | | | Fail 1 = 2
x.rego:4     | | Fail data.x.z
x.rego:7     | Enter data.x.z
x.rego:8     | | Fail 1 = 2

It then makes it super simple to see for each trace event where in the source code it is originating from with the format being filename:line. While we could add the column on too I'm not sure if we need it. This by itself makes it very easy to zero in on where the failure occurred in the source file.

Blokje5 added a commit to Blokje5/opa that referenced this issue Feb 11, 2020
Fixes open-policy-agent#2070

Signed-off-by: Lennard Eijsackers <lennardeijsackers92@gmail.com>
patrick-east pushed a commit that referenced this issue Feb 11, 2020
Fixes #2070

Signed-off-by: Lennard Eijsackers <lennardeijsackers92@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant