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

More stringent ast.ref_to_string #1106

Merged
merged 1 commit into from
Sep 12, 2024
Merged

More stringent ast.ref_to_string #1106

merged 1 commit into from
Sep 12, 2024

Conversation

anderseknert
Copy link
Member

While I started looking into #1104 I encountered some cases where ast.ref_to_string, and it's static counterpart would return wrong representations. We already had a bit of a homegrown format, which was convenient for some things, but would also leak out in places where it shouldn't be. Now use the same format as OPA for representing refs as strings.

Also added the query in error messages where we fail to prepare or eval in a couple of places, as the lack of those made debugging this issue much harder than it had to be.

While I started looking into #1104 I encountered some cases where
`ast.ref_to_string`, and it's `static` counterpart would return wrong
representations. We already had a bit of a homegrown format, which was
convenient for some things, but would also leak out in places where
it shouldn't be. Now use the same format as OPA for representing refs
as strings.

Also added the query in error messages where we fail to prepare or
eval in a couple of places, as the lack of those made debugging this
issue much harder than it had to be.

Signed-off-by: Anders Eknert <[email protected]>
Copy link
Member

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -575,7 +575,7 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) { // nolint:mai

responseParams := map[string]any{
"type": "opa-debug",
"name": "Debug " + path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

rs := ref_to_string(ref)
ss := substring(rs, 0, indexof(rs, ".$"))
str := _trim_from_var(rs, regex.find_n(`\[[^"]`, rs, 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the ref is foo.bar[7]? Or this isn't expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, for our purposes now, I think we'll want to eval only up to the first non-stringy path. But we can change that later.

@anderseknert anderseknert merged commit df31dda into main Sep 12, 2024
4 checks passed
@anderseknert anderseknert deleted the fix-eval-issue branch September 12, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants