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

map renders an error when it shouldn't. #647

Closed
ebobby opened this issue Aug 22, 2023 · 2 comments
Closed

map renders an error when it shouldn't. #647

ebobby opened this issue Aug 22, 2023 · 2 comments

Comments

@ebobby
Copy link
Contributor

ebobby commented Aug 22, 2023

Calling map with an array of objects where one of the objects doesn't have the given key, when strictVariables: true ends up in a weird interaction because of the call to _getFromScope.

Ruby simply returns nothing for those cases, liquidjs is instead rendering the error instead of throwing it.

    it('should not throw or render an error', function () {
      const posts = [{ category: 'foo' }, { name: 'bar' }]
      return test('{{posts | map: "category"}}', { posts }, 'foo', { strictVariables: true })
    })

This test results in:

  ● filters/array › map › should not throw or render an error

    expect(received).toBe(expected) // Object.is equality

    Expected: "foo"
    Received: "InternalUndefinedVariableError: undefined variable: category"

Notice how the error is rendered into the output string, and not even thrown. Ruby doesn't throw though, with strict vars and strict filiters it simply doesn't return anything. Yo would get "foo" as output for the given test.

@ebobby
Copy link
Contributor Author

ebobby commented Aug 22, 2023

I am not sure what features would break if I were to change that to be a regular object access and not use _getFromScope which seems to be causing the issue. Also I don't think I am smart enough to be able to follow all the generators chains. :(

@ebobby ebobby changed the title map doesn't properly report errors. map renders an error when it shouldn't. Aug 22, 2023
@harttle harttle added the bug label Aug 23, 2023
github-actions bot pushed a commit that referenced this issue Aug 23, 2023
## [10.9.1](v10.9.0...v10.9.1) (2023-08-23)

### Bug Fixes

* map filter allow nil results in strict mode, fixes [#647](#647) ([45adbd7](45adbd7))
@github-actions
Copy link

🎉 This issue has been resolved in version 10.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants