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

feat(deps): upgrade expr from 1.16.0 to 1.16.9 to support concat function. Fixes #13175 #13194

Merged
merged 4 commits into from
Jun 22, 2024

Conversation

jiachengxu
Copy link
Member

@jiachengxu jiachengxu commented Jun 16, 2024

Fixes #13175

Verification

Before this PR, creating the following workflow in the original issue:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: test-expression-
  namespace: argo
spec:
  entrypoint: main
  arguments:
    parameters:
      - name: expr
        value: "{{= concat(['a', 'b'], ['c', 'd']) | join('\\n') }}"
  templates:
    - name: main
      inputs:
        parameters:
          - name: expr
      script:
        image: alpine:3.6
        command: ["sh"]
        source: |
          echo result: '{{ inputs.parameters.expr }}'

it logs in the main container:

result: {{= concat([a, b], [c, d]) | join(n) }}

With this PR, it logs:

result: a
b
c
d

@jiachengxu jiachengxu changed the title feat: upgrade expr from 1.15.5 to 1.16.1 to support concat function. Fixes #13175 feat: upgrade expr from 1.16.0 to 1.16.1 to support concat function. Fixes #13175 Jun 16, 2024
@agilgur5 agilgur5 changed the title feat: upgrade expr from 1.16.0 to 1.16.1 to support concat function. Fixes #13175 feat(deps): upgrade expr from 1.16.0 to 1.16.1 to support concat function. Fixes #13175 Jun 16, 2024
@agilgur5 agilgur5 added type/dependencies PRs and issues specific to updating dependencies go Pull requests that update Go dependencies area/templating Templating with `{{...}}` labels Jun 16, 2024
go.mod Outdated Show resolved Hide resolved
@agilgur5 agilgur5 self-assigned this Jun 16, 2024
@jiachengxu jiachengxu changed the title feat(deps): upgrade expr from 1.16.0 to 1.16.1 to support concat function. Fixes #13175 feat(deps): upgrade expr from 1.16.0 to 1.16.9 to support concat function. Fixes #13175 Jun 16, 2024
@agilgur5
Copy link
Member

agilgur5 commented Jun 16, 2024

Looks like some of the tests are failing (unit and E2E) as the error message format is ever so slightly different. It seems like expr isn't giving a line number back anymore?

Error:      	Not equal: 
        	            	expected: "failed to dispatch event: failed to evaluate workflow template expression: unexpected token EOF (1:1)"
        	            	actual  : "failed to dispatch event: failed to evaluate workflow template expression: unexpected token EOF"

@jiachengxu
Copy link
Member Author

jiachengxu commented Jun 16, 2024

#13194 (comment)

Yes, right. Debugging the test locally and it seems like the line number, e.g., (1:1) is not there anymore

@jiachengxu
Copy link
Member Author

Is it OK if we just update the error message to make it match what expr currently returns?

@agilgur5
Copy link
Member

agilgur5 commented Jun 16, 2024

Yes I think that's fine. This actually might be a bug in expr, as it doesn't seem to be mentioned in the release notes anywhere. cc @antonmedv

@antonmedv
Copy link

Will take a look. Is there an example what reproduces the error?

@jiachengxu
Copy link
Member Author

Will take a look. Is there an example what reproduces the error?

@antonmedv Thanks for taking a look at this. You can use the following program to reproduce the issue:

package main

import (
	"log"

	"github.com/expr-lang/expr"
)

func main() {
	input := ""
	env := map[string]interface{}{
		"key": "value",
	}
	_, err := expr.Compile(input, expr.Env(env))
	if err != nil {
		log.Fatal(err)
	}
}

I also did some experiments and I narrowed the issue down to v1.16.8, before v1.16.8, the error is:

unexpected token EOF (1:1)

For version >= v1.16.8, the line number in the error is not available anymore, and the error message becomes the following:

unexpected token EOF

@antonmedv
Copy link

I took a look on why this error is here. Looks like in this case, as input is empty "", Expr does not add any more location information (I don't think it is useful in the case anyway).

I can just append this string to the error message + " (1, 1)" or we can the test (remote location part, or use Contains(t, "unexpected token EOF", err.Error())).

What do you think?

@jiachengxu
Copy link
Member Author

I took a look on why this error is here. Looks like in this case, as input is empty "", Expr does not add any more location information (I don't think it is useful in the case anyway).

I can just append this string to the error message + " (1, 1)" or we can the test (remote location part, or use Contains(t, "unexpected token EOF", err.Error())).

What do you think?

@antonmedv thank you for taking a look at this. Yes, I agree with you that in this case the location info doesn't help that much, I think we can just update our test by removing the location from the expected error message. @agilgur5 Please let me know your thought on this, if you agree, I can update tests this PR.

@agilgur5
Copy link
Member

agilgur5 commented Jun 18, 2024

I would say yes to both actually 😅

I don't think tests, in general, should rely on exact errors, as error specifics can change (and improving an error message, for instance, is usually not considered a breaking change). Especially if the source code does not rely on that specific error message; if it changes a bit, it's often not impactful. So @jiachengxu I think that change makes sense to do either way.

But I also think expr should have consistent errors, and it's not clear to me why this behavior changed. It is empty so the line number isn't very useful, but it makes sense to have it for consistency's sake. I also imagine there might be other users who's tests might break, so I think it would be good to add that back as well @antonmedv. Unless you had a good reason to remove it, but it seems like it was unintentional?

@antonmedv
Copy link

Expr provides errors during compilation from a few sources, some comes with a "snippet" |----------^.

My idea was to make this consistent across all errors. If an error contains a snippet |----^, add (line, column) to the error.

@antonmedv
Copy link

Also I was refactoring error location information from line and column for offsets start and end. This way it is possible to select the whole token with error.

@tooptoop4
Copy link
Contributor

i wonder if this helps with #13061 do u happen to use SSO RBAC @jiachengxu ?

Signed-off-by: Jiacheng Xu <[email protected]>
@jiachengxu
Copy link
Member Author

i wonder if this helps with #13061 do u happen to use SSO RBAC @jiachengxu ?

No, I am not using SSO RBAC feature for my setup

@jiachengxu
Copy link
Member Author

I have updated the tests to use Contains instead of Equal: bcbfef5

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

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

I have updated the tests to use Contains instead of Equal: bcbfef5

Yea that's what I usually do with these kinds of error message based tests.

LGTM, thanks for the update!

i wonder if this helps with #13061 do u happen to use SSO RBAC @jiachengxu ?

@tooptoop4 we'll want someone to test with :latest once this is merged and the image is released. The expr changelog didn't mention anything that I thought would affect it, but 🤷 It might've been something more innocuous like this change or could be a bug in the Argo portion of the templating logic

@agilgur5 agilgur5 enabled auto-merge (squash) June 22, 2024 02:07
@agilgur5 agilgur5 merged commit b49faaf into argoproj:main Jun 22, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/templating Templating with `{{...}}` go Pull requests that update Go dependencies type/dependencies PRs and issues specific to updating dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expr lang in argo: can't use concat function
4 participants