-
-
Notifications
You must be signed in to change notification settings - Fork 636
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
Type mismatches in await Get
s give unclear error message
#8349
Comments
Slightly grouchy comment, but: #7502 (comment) ... relates to #7509. |
Oh! There is a much, much easier way to fix 90% of cases of this one though: the constructor for pants/src/python/pants/engine/selectors.py Lines 86 to 87 in 44d4ab5
|
I tried doing this a few weeks ago. It fails because of union types :/ I couldn't come up with a clean fix. Inspecting -- @TansyArron and I came up with this error message:
Rust already has all the information needed to render this, including line numbers. We only need to implement it now. |
@herman5 said he's interested in taking this on 🎉 To formalize the problem a little more, the error happens when you do: await Get[A](B, z) where -- The goal is to say something like this:
Please feel free to improve this! -- You'll need to change this: pants/src/rust/engine/src/nodes.rs Lines 765 to 813 in a154c84
Line 809 is what you'll want to change. You can get the declared product type ( pants/src/rust/engine/src/nodes.rs Lines 778 to 779 in a154c84
I'm not totally sure how to get the declared subject type ( I think pants/src/rust/engine/src/core.rs Lines 166 to 182 in a154c84
This generates a value like You might also find this https://github.com/pantsbuild/pants/blob/master/src/rust/engine/src/tasks.rs helpful to see how we generally represent a rule in graph error messages. See the type -- Finally, you'll want to make sure that |
yield Get
s give unclear error messageawait Get
s give unclear error message
Before: > Exception: WithDeps(Inner(InnerEntry { params: {Specs, Console}, rule: Task(Task { product: List, can_modify_workunit: false, clause: [Addresses, ListSubsystem, Console], gets: [Get { output: UnexpandedTargets, input: Addresses }], func: pants.backend.project_info.list_targets:64:list_targets(), cacheable: false, display_info: DisplayInfo { name: "pants.backend.project_info.list_targets.list_targets", desc: Some("`list` goal"), level: Debug } }) })) did not declare a dependency on JustGet(Get { output: UnexpandedTargets, input: int }) After: ``` Engine traceback: in select in pants.backend.project_info.list_targets.list_targets Traceback (most recent call last): File "/Users/eric/DocsLocal/code/projects/pants/src/python/pants/engine/internals/native.py", line 65, in generator_send res = func.send(arg) File "/Users/eric/DocsLocal/code/projects/pants/src/python/pants/backend/project_info/list_targets.py", line 79, in list_targets targets = await Get(UnexpandedTargets, Addresses, 123) File "/Users/eric/DocsLocal/code/projects/pants/src/python/pants/util/meta.py", line 182, in new_init prev_init(self, *args, **kwargs) File "/Users/eric/DocsLocal/code/projects/pants/src/python/pants/engine/internals/selectors.py", line 159, in __init__ self.input = self._validate_input(input_arg1, shorthand_form=False) File "/Users/eric/DocsLocal/code/projects/pants/src/python/pants/engine/internals/selectors.py", line 201, in _validate_input f"Invalid Get. The third argument `{input_}` must have the exact same type as the " TypeError: Invalid Get. The third argument `123` must have the exact same type as the second argument, pants.engine.addresses.Addresses, but had the type <class 'int'>. ``` Note that the stacktrace includes the offending `Get`, including the line and file where it's set. This is because we now eagerly validate in the Python constructor for `Get`. We can only apply this new error message for non-union `Get` calls; the engine must handle type errors relating to `unions` because Python does not have knowledge of `UnionMembership` in the `Get` constructor. Closes #8349.
If you do something like:
snapshot = yield Get(Snapshot, PathGlobs, "foo")
where there is a type mismatch between the declared parameter type, and the actual parameter type, you get an error:
Talking about "did not declare a dependency" is really misleading; this error message should read more like:
"Did not have a set of rules installed to transform from a
str
to aSnapshot
, which you tried to do in file X on line Y"and maybe even a hint along the lines of "You declared that the argument to be of type
PathGlobs
but it was actually of typestr
".The text was updated successfully, but these errors were encountered: