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

Fix confusing error for an @console_rule not returning a Goal #8931

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

Eric-Arellano
Copy link
Contributor

Closes #8930.

Copy link
Contributor

@TansyArron TansyArron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@gshuflin
Copy link
Contributor

gshuflin commented Jan 9, 2020

I'm not sure if we actually want to enforce that @console_rules must return a subclass of Goal. In principle a console_rule should be able to invoke another console_rule, right?

@Eric-Arellano
Copy link
Contributor Author

In principle a console_rule should be able to invoke another console_rule, right?

Should they? I don't think so, personally. My mental model for console_rule has always been "the rule associated with a top-level goal." That comes from the name.

Instead, I think your mental model might be closer to "a rule that should not be cached"? That detail comes more from the implementation. If we wanted console rules to be able to call console rules, then I think console_rule would be a misnomer and we should instead have a name like uncachable_rule.

@gshuflin
Copy link
Contributor

gshuflin commented Jan 9, 2020

Instead, I think your mental model might be closer to "a rule that should not be cached"? That detail comes more from the implementation. If we wanted console rules to be able to call console rules, then I think console_rule would be a misnomer and we should instead have a name like uncachable_rule.

Exactly. And I'm not personally sure whether the important thing about @console_rule-like rules is that they are top-level, or that they are uncacheable. This commit would reify the former interpretation in code, and then we would have no way of talking about an uncacheable rule that doesn't return a Goal class. If the latter interpretation is the important one, then you are right that it would make sense to rename this annotation to something like @uncacheable_rule.

cf. the discussion on #8922

@Eric-Arellano
Copy link
Contributor Author

Exactly. And I'm not personally sure whether the important thing about @console_rule-like rules is that they are top-level, or that they are uncacheable. This commit would reify the former interpretation in code, and then we would have no way of talking about an uncacheable rule that doesn't return a Goal class. If the latter interpretation is the important one, then you are right that it would make sense to rename this annotation to something like @uncacheable_rule.

I think it will always make sense to have @console_rule. I've found it a useful concept when teaching folks about how V2 works and especially how to implement Goals in V2. It indicates that there is some special magic that distinguishes @rule from @console_rule. Removing @console_rule in favor of @uncachable_rule would no longer clearly express this, and then we could no longer have this PR's check to ensure that the console rule is returning a Goal.

Instead, we would add a new rule type called @uncachable_rule, which is simply a wrapper of @rule(cachable=False).

--

Whether we add @uncachable_rule or not, I think we should keep @console_rule, meaning that this PR would help the rule authoring experience.

@TansyArron
Copy link
Contributor

@gshuflin - Currently if you write an @console_rule that doesn't return a Goal the engine throws an error stating that "@rules that return Goals must be @console_rules" which is supremely unhelpful.

So whether we should accept @console_rules that return things other than goals or not seems to be a different question. This PR is just improving the confusing error message and not actually changing the behavior of pants.

Copy link
Contributor

@codealchemy codealchemy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gshuflin
Copy link
Contributor

gshuflin commented Jan 9, 2020

Ok, @TansyArron @Eric-Arellano I think I agree that this commit is okay as-is and the discussion about how to handle rule cacheability correctly is something that should be punted on.

@Eric-Arellano Eric-Arellano merged commit 670f898 into pantsbuild:master Jan 9, 2020
@Eric-Arellano Eric-Arellano deleted the console-rule-error branch January 9, 2020 22:47
Eric-Arellano added a commit that referenced this pull request Jan 10, 2020
Any time that you add a new top-level goal in V2—that is a "verb" for Pants like `test`, `fmt`, `setup-py`, and `dependencies`—you must define the same three basic things:

```
Goal, GoalSubsystem, @console_rule
```

One of those does not fit with the other two. In contrast, these three all belong:

```
Goal, GoalSubsystem, @goal_rule
```

### What is an `@console_rule`?

There are (at least) 3 ways of conceptualizing what an `@console_rule` means:

1. A rule that has exclusive access to the `Console`.
    * Only `@console_rules` can write to stdout and stderr.
    * This property is represented in the name `@console_rule`.
2. A rule that is not cached.
    * This is an important property of `@console_rules` and contrasts with normal `@rules`.
    * Per the conversation in #8931 (comment), this idea on uncachability is the main mental model for some.
3. A rule that maps 1-1 with a top-level goal / returns an `engine.goal.Goal`.

All three of these properties are true and important components of an `@console_rule`. However, I argue that #3 is the most important: _fundamentally, an `@console_rule` is a special rule that hooks up to a Pants goal_.

Right now, the name `@console_rule` optimizes for property #1. In contrast, `@goal_rule` focuses on property #3. 

(NB: all three of these properties will continue applying regardless of the name)

### Leveraging prior Pants knowledge

Most Pants users are familiar with the idea of a goal. It's the [very first concept introduced in our docs](https://www.pantsbuild.org/first_concepts.html) and every single Pants run involves invoking goals, regardless of V1 vs. V2.

In contrast, fewer users are familiar with the `Console` abstraction, which is never mentioned in our docs and is more of an implementation detail for how V2 Pants works.

We do expect users to soon write their own rules in plugins. The name `@goal_rule` will allow them to leverage their prior knowledge, just as `subsystem_rule` leverages prior knowledge better than `optionable_rule` did.
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

Successfully merging this pull request may close these issues.

Bad Error message when a rule is marked @console_rule but does not produce a Goal.
4 participants