This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new a7041feff3 Minor: Add an example for backtrace pretty print (#11450)
a7041feff3 is described below

commit a7041feff32c2af09854c144a760d945e30fb38a
Author: Jax Liu <[email protected]>
AuthorDate: Sun Jul 14 05:47:47 2024 +0800

    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]>
---
 docs/source/user-guide/crate-configuration.md | 44 ++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/docs/source/user-guide/crate-configuration.md 
b/docs/source/user-guide/crate-configuration.md
index 0587d06a39..9d22e34030 100644
--- a/docs/source/user-guide/crate-configuration.md
+++ b/docs/source/user-guide/crate-configuration.md
@@ -121,7 +121,7 @@ backtrace:    0: 
std::backtrace_rs::backtrace::libunwind::trace
 
 The backtraces are useful when debugging code. If there is a test in 
`datafusion/core/src/physical_planner.rs`
 
-```
+```rust
 #[tokio::test]
 async fn test_get_backtrace_for_failed_code() -> Result<()> {
     let ctx = SessionContext::new();
@@ -141,6 +141,48 @@ To obtain a backtrace:
 ```bash
 cargo build --features=backtrace
 RUST_BACKTRACE=1 cargo test --features=backtrace --package datafusion --lib -- 
physical_planner::tests::test_get_backtrace_for_failed_code --exact --nocapture
+
+running 1 test
+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...
 ```
 
 Note: The backtrace wrapped into systems calls, so some steps on top of the 
backtrace can be ignored
+
+To show the backtrace in a pretty-printed format use `eprintln!("{e}");`.
+
+```rust
+#[tokio::test]
+async fn test_get_backtrace_for_failed_code() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "select row_numer() over (partition by a order by a) from 
(select 1 a);";
+
+    let _ = match ctx.sql(sql).await {
+        Ok(result) => result.show().await?,
+        Err(e) => {
+            eprintln!("{e}");
+        }
+    };
+
+    Ok(())
+}
+```
+
+Then run the test:
+
+```bash
+$ RUST_BACKTRACE=1 cargo test --features=backtrace --package datafusion --lib 
-- physical_planner::tests::test_get_backtrace_for_failed_code --exact 
--nocapture
+
+running 1 test
+Error during planning: Invalid function 'row_numer'.
+Did you mean 'ROW_NUMBER'?
+
+backtrace:    0: std::backtrace_rs::backtrace::libunwind::trace
+             at 
/rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
+   1: std::backtrace_rs::backtrace::trace_unsynchronized
+             at 
/rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
+   2: std::backtrace::Backtrace::create
+             at 
/rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/backtrace.rs:331:13
+   3: std::backtrace::Backtrace::capture
+   ...
+```


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to