Skip to content

Commit

Permalink
doc: Describe relevant error modes during rule compilation (#18663)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobni authored Apr 6, 2023
1 parent 8a8f957 commit c49e56a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/python/pants/engine/internals/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,31 @@ def test_outlined_get() -> None:
with pytest.raises(ExecutionError) as exc:
rule_runner.request(int, [])
assert (
"Get(int, str, hello) was not detected in your @rule body at rule compile time. "
"Was the `Get` constructor called in a separate function, or perhaps "
"dynamically? If so, it must be inlined into the @rule body."
"Get(int, str, hello) was not detected in your @rule body at rule compile time."
) in str(exc.value.args[0])


@rule
async def uses_rule_helper_before_definition() -> int:
return await get_after_rule()


async def get_after_rule() -> int:
return await Get(int, str, "hello")


def test_rule_helper_after_rule_definition_fails() -> None:
rule_runner = RuleRunner(
rules=[
uses_rule_helper_before_definition,
QueryRule(int, []),
],
)

with pytest.raises(ExecutionError) as exc:
rule_runner.request(int, [])
assert (
"Get(int, str, hello) was not detected in your @rule body at rule compile time."
) in str(exc.value.args[0])


Expand Down
5 changes: 3 additions & 2 deletions src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,9 @@ impl Task {
// `type(input) != input_type`.
throw(format!(
"{get} was not detected in your @rule body at rule compile time. \
Was the `Get` constructor called in a separate function, or perhaps \
dynamically? If so, it must be inlined into the @rule body.",
Was the `Get` constructor called in a non async-function, or \
was it inside an async function defined after the @rule? \
Make sure the `Get` is defined before or inside the @rule body.",
))
}
})?;
Expand Down

0 comments on commit c49e56a

Please sign in to comment.