-
Notifications
You must be signed in to change notification settings - Fork 299
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
cmd/cue: unclear how to validate selector and qualified identifier errors #629
Comments
Original reply by @mpvl in cuelang/cue#629 (comment) Like with Go, one should distinguish a reference from a selector. A missing reference, the first This is the only reference of In the case of the package one could argue the user has no control over adding more values and thus the error should be terminal, but also terminal evaluation errors simply get eliminated as a disjunct. I'm not sure what errors you would want to present to the user in this case, as these really aren't errors. A linter could maybe complain about the package reference, assuming that packages are static. But the A different story would be if |
Original reply by @myitcv in cuelang/cue#629 (comment)
Indeed, which is why I included all three, as a compare and contrast. The case of a bad reference is I agree clear.
Yes, the case of a package selector is what gave rise to this case.
You're quite right, I intended for my example using
In the case of the package and definition selectors (cases |
Original reply by @mpvl in cuelang/cue#629 (comment)
It probably makes sense to do something very similar to what Go does, and automatically trigger such errors for |
Original reply by @mpvl in cuelang/cue#629 (comment) FTR: internally, CUE marks For |
Original reply by @myitcv in cuelang/cue#629 (comment) @mpvl I suggest we at least consider this for |
Using the go API, I'd love to have an option I can pass to So that cases like In my case I can't use |
I just referenced a few issues from dagger. Users are getting confused because typos are leading to unexpected errors elsewhere and it's hard to understand why. At least now I understand it a bit more to be able to help them, but should we be doing something differently? I follow what @eonpatapon is saying, it's the same here. |
@helderco please can you provide examples of the issues people are seeing in Dagger? We should categorise them to ensure they are either covered by the cases described in the description of this issue, or to add to that list. Thanks |
@eonpatapon there is precedent for your suggestion; it aligns with the use of Lines 747 to 752 in c942d0a
But clearly So the suggestion of having cc @mpvl |
They're essentially about those two situations:
Except that instead of referencing from a disjunction they're being referenced from a cue/flow task which is making the task not run, and thus leading to all sorts of unexpected behavior elsewhere (missing dependency values). |
@helderco please can you provide complete examples so that we can validate the solution suggested by @eonpatapon (and indeed any others)? |
Yes I planned on doing that today but I just haven’t been able to get to it yet. |
There's an example from:
It doesn't fail as we'd expect, but we're also seeing that the task isn't running (not sure how to reproduce here). We're seeing this because of typos. |
I believe the solution suggested by @eonpatapon should work for us. We'll try and provide some additional examples. We did manage to implement a workaround for now, which is to walk through the values and check On a general note, I've re-read through the comments and still cannot understand why referencing something that doesn't exist doesn't throw an error. The evaluator is clearly aware of that since there's something in |
Thanks. Seeing real Dagger examples will help to understand the context here. The example that @helderco links to above is a |
Edit comment: I have just updated the title and description of this issue to remove the reference to "disjunctions". This issue is primarily being referenced because of the UX issues caused by a lack of errors in selector and qualified identifier references. The case of disjunctions is also interesting/important, but we should focus on that non-disjunction case first. |
Here's an incomplete cause disjunction we're seeing.
> exec cue eval x.cue -c
[stderr]
m: incomplete cause disjunction Just another side effect of Expected to see Related: |
@helderco thanks. Please can you share Dagger examples for these "problem" scenarios? Reason being, I think what we're discussing here is an (important) issue of UX, and whether/when certain state is surfaced as an "error" or not. That means we really need to see situations where Dagger users expect to see an "error" but have not. (Note I am using "error" here to indicate the user's expectation of "I expected to see an error reported by Dagger/my editor because what I have written is wrong/doesn't work" rather than any specific type of error as defined by CUE). |
They're always about typos that users make. Instead of the plan failing, actions just got "dropped" (not executed), which leads to unexpected errors elsewhere because values aren't being filled by their dependencies. The problem is the error message doesn't point to the origin of the issue, but to a side-effect of it, which leads to confusion. The issues have more context. They're now closed because we've added validation, but I'm compiling a couple examples here so you get an ideia. Typos in imports:
So a user may use package main
import (
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/python"
)
dagger.#Plan & {
actions: {
_fs: core.#WriteFiles & { // typo, doesn't fail here
input: dagger.#Scratch
path: "/test.py"
contents: "print('foobar')"
}
test: python.#Run & {
script: {
directory: _fs.output // fails on an internal field that depends on this, since it's empty/inconcrete
filename: "test.py"
}
}
}
}
// OUTPUT:
// failed to load plan: actions.test.mounts."Python script": 1 errors in empty disjunction: Expected:
Typos in references to a non-existing field in an open struct
These also lead to actions being dropped and producing errors relating to side-effects. Here's a simple example: package main
import (
"dagger.io/dagger"
"universe.dagger.io/python"
)
dagger.#Plan & {
client: filesystem: ".": read: contents: dagger.#FS
actions: {
test: python.#Run & {
script: {
directory: client.filesystem."./".read.contents // typo in the path, doesn't match to any action
filename: "test.py"
}
}
}
} ConclusionHere's what @aluzzardi concluded:
Originally posted in dagger/dagger#493 (comment) I hope this helps. |
Please can you confirm the expected behaviour in this case?
Please can you or @aluzzardi confirm the expected output in this situation? i.e. ignoring the POC/solution you have now, which "errors" would you expect to be flagged in an ideal world? |
We expect the undefined fields to fail during load, before anything else. Because these lead to other types of errors.
|
The client: {
env: KUBECONFIG: string
filesystem: (env.KUBECONFIG): read: contents: string
} So In that case we wouldn't want to fail on load with |
I guess it's the same with actions: {
foo: core.#Nop & {
input: actions.bar
}
if foo.output == "success" {
bar: core.#Nop & {
input: "foobar"
}
}
} |
Disregard my last example, it's not a good one. Not sure how you'd depend on a field that might not exist. |
I think it depends how you evaluate cue. If using the go api after the first evaluation even if there is some missing references you can still use In the case of For command: x: {
a: http.Get & {
url: "..."
response: body: string
decoded: json.Unmarshal(response.body)
}
b: cli.Print & {
text: a.decoded.foo.bar
}
} Technically before the flow is run
|
In relation to this issue, I have been using |
@hectorj2f yes, a similar "issue" exists for |
Originally opened by @myitcv in cuelang/cue#629
What version of CUE are you using (
cue version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
Consider the following:
gives the following:
This error above is as expected.
According to my reading of the spec, boths.y
andfn.y
evaluate to_|_
. Hence, strictly speaking, the output above is correct.But the lack of errors for lines 8 and 9 are tricky as the author of this code. I have no way of knowing that I have referenced non-existent fields until evaluation time.
My error has been masked by the use of a disjunction.Note: this repro is derived from a real-world example where this typo was made across tens of files.
What did you expect to see?
Unclear, because it's conceivable that a different user might have intended the above behaviour, and so not expect to see errors for
s.y
orfn.y
cc @jlongtine
2022-05-03 edit: removed use of disjunctions, because this issue is primarily being referenced because of the lack of errors/UX issues that come with incomplete references. The disjunction case is an interesting extension of that same problem, but is one we necessarily need to solve second.
The text was updated successfully, but these errors were encountered: