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

Consider reviewing type-check consistency of function arguments #168

Open
springcomp opened this issue Jun 19, 2023 · 1 comment
Open

Consider reviewing type-check consistency of function arguments #168

springcomp opened this issue Jun 19, 2023 · 1 comment

Comments

@springcomp
Copy link
Contributor

springcomp commented Jun 19, 2023

Some functions are defined as taking arguments of a specific type, but are still allowed to return null when given invalid types.

For instance the ceil() function returns null on invalid input in the original implementations.
This seems to contradict the blanket statement from the specification that:

“Function arguments have types. If an argument for a function has the wrong type, an invalid-type error will occur.”

JMESPath Community implementations enforce strict type checking as much as possible, unless a compliance test exists.
Please, consider reviewing type-checking and make it more consistent.

Maybe this should be documented in the compatibility section of the compliance test suite?

@hell-racer
Copy link

hell-racer commented Jun 19, 2023

From my perspective (and from what I think 'convenience' point of view) it would be nice if all functions returned null if argument is null and throw exception if the argument is of wrong type. Usually if an argument has incorrect type means that you have an error in your expression, and if an argument is null - usually means that your expression is correct but the data lacks something (which is usually ok). Functions throwing if argument is null means that all the expressions are cluttered with 'fallback' values, e.g. instead of length(a) you have length(a || '') (or a && length(a)) all over the place. It is extremely visible when you have large templates that consist only of JmesPath expressions.
Now, there are some edge cases... E.g. it would be nice if join() just skipped null values and automatically converted numbers to strings (and throw if there are some objects or arrays among items).

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

No branches or pull requests

2 participants