-
Notifications
You must be signed in to change notification settings - Fork 272
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
[JSONSelection] Support variadic $(...)
function
#6456
base: next
Are you sure you want to change the base?
Conversation
❌ Docs Preview FailedError
|
CI performance tests
|
} | ||
// As long as the expressions keep evaluating to None, keep | ||
// accumulating errors in all_errors. | ||
all_errors.extend(expr_errors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if all subexpressions in $(a, b, c)
, we'd see four errors? (one for each subexpression plus the No $(...) expression evaluated successfully
)
is there value in the errors for each subexpression? seems like the last error gives you all the information you need, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's some value in the subexpression errors because they're the ones that will tell you which property specifically was missing, if the expression could fail in multiple ways.
Since there's a sort of hierarchical structure to the errors, maybe it doesn't make sense to lump them all into one array, but instead store the subexpression errors as children of the final error somehow? Then you'd dig into those errors only if you needed to explain the final error in more detail.
8f4c23d
to
62775ad
Compare
909e897
to
e5eedde
Compare
e5eedde
to
16d0306
Compare
16d0306
to
dfeb558
Compare
Detected SAST Vulnerabilities🔴 Potential Security Issues FoundIf you are seeing this message, it means that the security scanning tool that Apollo uses to test our source has identified a potential security issue in code introduced or updated via your branch. Information about what was detected and steps to move forward are below. If the scanner detected a legitimate issue, please take action to correct it prior to merging this PR. The action required will vary based on the detection. If the detection is a false positive, please follow the steps below to resolve the issue. Issues Detected
|
This allows us to postpone PR #6456 for further consideration.
This allows us to postpone PR #6456 for further consideration.
This allows us to postpone PR #6456 for further consideration.
This allows us to postpone PR #6456 for further consideration.
When it takes a single argument, the
$(...)
function (akaExprPath
syntax, introduced in #5994), is useful for embedding literal values into selection syntax.This PR generalizes the
$(...)
function to take one or more arguments, where the first argument that evaluates toSome(JSON)
instead ofNone
is returned, allowing default expressions like$(possiblyEmptyList->first, {})
or$($args.possibly.missing, null)
. A benefit of this syntax is that it's insensitive to whether the first expression failed because$args.possibly
was missing or because$args.possibly.missing
was missing. The whole expression evaluated (in theapply_to_path
sense) toNone
, for whatever reason, so the$(...)
function moves on to the next option.Passing more than two arguments is also possible, as in
$(maybe.this, maybe.that, false)
.Like many
->
functions, the$(...)
syntax evaluates its arguments lazily, so any arguments passed after the one returned will remain fully unevaluated. This makes it possible to use a (hypothetical)->withError(message)
method to report errors only when an expression is evaluated:It may also be worth noting that methods like
->match
can evaluate toNone
if they do not have an infallible[@, ...]
catch-all case, or if the matched value expression evaluates toNone
. In principle, you could use the$(...)
function to provide a catch-all default, like so:The
->match
method will normally produce a runtimeApplyToError
when it exhausts all its cases, but the$(...)
function hides those errors as long as one of its options evaluates toSome(JSON)
. If they all fail (i.e. evaluate toNone
), then all the original runtimeApplyToError
s will be returned.