Skip to content

Commit a7041fe

Browse files
goldmedalcomphead
andauthored
Minor: Add an example for backtrace pretty print (#11450)
* add the example for printing backtrace pretty * add empty end line * fix prettier * sync the usage example * Update docs/source/user-guide/crate-configuration.md Co-authored-by: Oleks V <[email protected]> --------- Co-authored-by: Oleks V <[email protected]>
1 parent a43cf79 commit a7041fe

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

docs/source/user-guide/crate-configuration.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ backtrace: 0: std::backtrace_rs::backtrace::libunwind::trace
121121
122122
The backtraces are useful when debugging code. If there is a test in `datafusion/core/src/physical_planner.rs`
123123
124-
```
124+
```rust
125125
#[tokio::test]
126126
async fn test_get_backtrace_for_failed_code() -> Result<()> {
127127
let ctx = SessionContext::new();
@@ -141,6 +141,48 @@ To obtain a backtrace:
141141
```bash
142142
cargo build --features=backtrace
143143
RUST_BACKTRACE=1 cargo test --features=backtrace --package datafusion --lib -- physical_planner::tests::test_get_backtrace_for_failed_code --exact --nocapture
144+
145+
running 1 test
146+
Error: Plan("Invalid function 'row_numer'.\nDid you mean 'ROW_NUMBER'?\n\nbacktrace: 0: std::backtrace_rs::backtrace::libunwind::trace\n at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5\n 1: std::backtrace_rs::backtrace::trace_unsynchronized\n...
144147
```
145148
146149
Note: The backtrace wrapped into systems calls, so some steps on top of the backtrace can be ignored
150+
151+
To show the backtrace in a pretty-printed format use `eprintln!("{e}");`.
152+
153+
```rust
154+
#[tokio::test]
155+
async fn test_get_backtrace_for_failed_code() -> Result<()> {
156+
let ctx = SessionContext::new();
157+
158+
let sql = "select row_numer() over (partition by a order by a) from (select 1 a);";
159+
160+
let _ = match ctx.sql(sql).await {
161+
Ok(result) => result.show().await?,
162+
Err(e) => {
163+
eprintln!("{e}");
164+
}
165+
};
166+
167+
Ok(())
168+
}
169+
```
170+
171+
Then run the test:
172+
173+
```bash
174+
$ RUST_BACKTRACE=1 cargo test --features=backtrace --package datafusion --lib -- physical_planner::tests::test_get_backtrace_for_failed_code --exact --nocapture
175+
176+
running 1 test
177+
Error during planning: Invalid function 'row_numer'.
178+
Did you mean 'ROW_NUMBER'?
179+
180+
backtrace: 0: std::backtrace_rs::backtrace::libunwind::trace
181+
at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
182+
1: std::backtrace_rs::backtrace::trace_unsynchronized
183+
at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
184+
2: std::backtrace::Backtrace::create
185+
at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/backtrace.rs:331:13
186+
3: std::backtrace::Backtrace::capture
187+
...
188+
```

0 commit comments

Comments
 (0)