-
Notifications
You must be signed in to change notification settings - Fork 447
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
std.mergePatch can't merge over error values #414
Comments
also note, in the specific example cases above you could replace std.mergePatch(
{ a: { b: { c: { d: error "nope" } } } },
{ a: { bb: [stuff], b: { c: { d: { stuff: [morestuff] } } } } } # Imported from plain JSON
) ... where mergePatch is needed. |
Makes sense. Actually it makes so much sense we're already almost doing this. It would be enough to remove
It seems to me that it still wouldn't help:
Perhaps a better solution would be to have a fancy version of mergePatch which gets a schema of target object as an argument. I'm not sure. |
To paraphrase the question: "I can't implement the laziness of mixin composition with std.mergePatch because it deeply evaluates both sides even if the RHS wins". Two more examples:
Why is mergePatch needed here? It is possible to do this:
and get
edit: Never mind, you cannot put a +: into raw JSON, I understand. |
The problem I think is that with + you can choose between The fundamental problem here may be that taking std.mergePatch() (which is designed for operation on raw data) and using it in a context where the LHS is not a computable object. For your case, maybe one of these options will help:
|
I don't understand the argument about tailstrict. Here is the code:
If |
I am more and more thinking that what you want to do is
|
This evaluates just fine as it is,
But in the original example it's wrapped in an object:
Both
which is effectively:
This forces both arguments, even though |
I see what you mean, but in his case (RHS is an object) it will be forced internally anyway, even if it is not forced in the tail call. |
@benley Did the workaround work, can I close this? |
Yeah - sorry I never followed up on this one after the initial discussion. I'm comfortable with implementing application error values at a higher level than the jsonnet |
No worries, I have added this to my list of "things that would easier if we could catch exceptions" |
I was hoping that this would work:
but unfortunately that results in a runtime error, because mergePatch has to check the type of each field, and
std.type(error "err")
is also a runtime error.I think it would be possible to make the above example work by checking the type of the replacement value before considering the original value, and ignoring the original value unless the replacement is an object. But it still wouldn't be possible to do this:
So now I'm wondering: Would it break the world to make
std.type(error "nope")
return"error"
instead of an error? Or as an alternative, what about adding a boolean stdlib function likestd.isError(x)
?The text was updated successfully, but these errors were encountered: