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

Error "unknown context value" Raised After Checking for Existence #713

Closed
1 task done
mi25iw opened this issue Apr 19, 2024 · 2 comments · Fixed by #715
Closed
1 task done

Error "unknown context value" Raised After Checking for Existence #713

mi25iw opened this issue Apr 19, 2024 · 2 comments · Fixed by #715
Labels
bug Something isn't working pkg:json-e

Comments

@mi25iw
Copy link
Contributor

mi25iw commented Apr 19, 2024

Nuget Package

JsonE.Net

Package Version

2.1.0

Operating System

Windows

.Net Target (if relevant, please specify the version in the description)

.Net (5 or after)

A clear and concise description of the bug.

After an if (or switch) statement that checks if a variable/key exists, the then statement throws an unknown context value error even though the if check was false. For example, the sample for defined() on the json-e page works in the online playground there but causes this error in JsonE.Net.

What did you expect?

When an if or switch statement evaluates false, errors should not be thrown for non-existent values in the untaken branch.

Please add test code or steps to reproduce the behavior.

Here are a few tests in the more-tests.yml format that fail, and my understanding from reading the spec and using the online playground is that they should pass:

---
title:    if defined check
context:  {y: 10}
template: {$if: 'defined("x")', then: {$eval: 'x'}, else: 20}
result:   20
---
title:    switch defined check
context:  {y: 10}
template: {$switch: {'defined("x")': {$eval: 'x'}, $default: 20}}
result:   20

The template can be copied to the playground to verify that at least in their implementation, this is supported.

Is there any other information you'd like to share regarding this bug?

If this issue is accepted, it'd be great for these tests to be incorporated in the official json-e test suite in case it exists in other implementations.

Code of Conduct & Contributor Guidelines

  • I agree to follow this project's Code of Conduct and Contribution Guidelines.
@mi25iw mi25iw added the bug Something isn't working label Apr 19, 2024
@gregsdennis
Copy link
Collaborator

Thanks for contributing these tests!

I should be able to work this out shortly. My guess is that I'm evaluating the branches before I know whether I need to.

@mi25iw
Copy link
Contributor Author

mi25iw commented Apr 19, 2024

I put up a PR, seemed like an easy enough change. Assuming the switch change didn't introduce a subtle issue.

EDIT: Hey, funny timing! I was writing this before you commented, although you beat me to the punch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:json-e
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants