Skip to content

Commit

Permalink
Render all frames of a failure in Engine tracebacks (pantsbuild#10510)
Browse files Browse the repository at this point in the history
### Problem

Currently only workunits with user-visible descriptions will be rendered in engine tracebacks, and this inhibits debugging.

### Solution

Since `--print-exception-stacktrace` is disabled by default, we can safely be more specific, and render the workunit name (ie, rule name) if a workunit does not have a description.

### Result

```
Engine traceback:
  in `dependencies` goal
Traceback (most recent call last):
  <snip>
```
becomes
```
Engine traceback:
  in select
  in `dependencies` goal
  in pants.engine.internals.graph.resolve_targets
  in pants.engine.internals.graph.resolve_target
  in pants.engine.internals.graph.generate_subtargets
  in pants.engine.internals.build_files.find_target_adaptor
Traceback (most recent call last):
  <snip>
```

[ci skip-build-wheels]
  • Loading branch information
stuhood authored Jul 31, 2020
1 parent 059e646 commit 0b7d9e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/python/pants/engine/internals/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def test_include_trace_error_raises_error_with_trace(self):
"""
1 Exception encountered:
Engine traceback:
in select
in pants.engine.internals.engine_test.nested_raise
Traceback (most recent call last):
File LOCATION-INFO, in nested_raise
fn_raises(x)
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/engine/internals/scheduler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test_trace_includes_rule_exception_traceback(self):
1 Exception encountered:
Engine traceback:
in select
in Nested raise
Traceback (most recent call last):
File LOCATION-INFO, in nested_raise
Expand Down
9 changes: 5 additions & 4 deletions src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,8 +1150,11 @@ impl Node for NodeKey {

let user_facing_name = self.user_facing_name();
let workunit_name = self.workunit_name();
let failure_name = user_facing_name
.clone()
.unwrap_or_else(|| workunit_name.clone());
let metadata = WorkunitMetadata {
desc: user_facing_name.clone(),
desc: user_facing_name,
message: None,
level: self.workunit_level(),
blocked: false,
Expand Down Expand Up @@ -1220,9 +1223,7 @@ impl Node for NodeKey {
}
};

if let Some(user_facing_name) = user_facing_name {
result = result.map_err(|failure| failure.with_pushed_frame(&user_facing_name));
}
result = result.map_err(|failure| failure.with_pushed_frame(&failure_name));

// If both the Node and the watch failed, prefer the Node's error message.
match (&result, maybe_watch) {
Expand Down

0 comments on commit 0b7d9e4

Please sign in to comment.