From 1a517115f47e56e2136d40f932692202ad4544c4 Mon Sep 17 00:00:00 2001 From: xxchan Date: Mon, 19 May 2025 12:30:25 +0800 Subject: [PATCH 1/2] feat: expose `Error::backtrace()` Signed-off-by: xxchan --- crates/iceberg/src/error.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/iceberg/src/error.rs b/crates/iceberg/src/error.rs index 88410826f..30c346da8 100644 --- a/crates/iceberg/src/error.rs +++ b/crates/iceberg/src/error.rs @@ -256,6 +256,42 @@ impl Error { self } + /// Return error's backtrace. + /// + /// Note: the standard way of exposing backtrace is the unstable feature [`error_generic_member_access`](https://github.com/rust-lang/rust/issues/99301). + /// We don't provide it as it requires nightly rust. + /// + /// If you just want to print error with backtrace, use `Debug`, like `format!("{err:?}")`. + /// + /// If you use nightly rust, and want to access `iceberg::Error`'s backtrace in the standard way, you can + /// implement a newtype like this: + /// + /// ```ignore + /// // assume you already have `#![feature(error_generic_member_access)]` on the top of your crate + /// + /// #[derive(::std::fmt::Debug)] + /// pub struct IcebergError(iceberg::Error); + /// + /// impl std::fmt::Display for IcebergError { + /// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + /// self.0.fmt(f) + /// } + /// } + /// + /// impl std::error::Error for IcebergError { + /// fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) { + /// request.provide_ref::(self.0.backtrace()); + /// } + /// + /// fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + /// self.0.source() + /// } + /// } + /// ``` + pub fn backtrace(&self) -> &Backtrace { + &self.backtrace + } + /// Return error's kind. /// /// Users can use this method to check error's kind and take actions. From 72c88c6bb14d5d2edb93a54c7c6c780a6475e0ef Mon Sep 17 00:00:00 2001 From: xxchan Date: Mon, 19 May 2025 12:33:31 +0800 Subject: [PATCH 2/2] clippy Signed-off-by: xxchan --- crates/iceberg/src/error.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/iceberg/src/error.rs b/crates/iceberg/src/error.rs index 30c346da8..37529ee6f 100644 --- a/crates/iceberg/src/error.rs +++ b/crates/iceberg/src/error.rs @@ -288,6 +288,13 @@ impl Error { /// } /// } /// ``` + /// + /// Additionally, you can add a clippy lint to prevent usage of the original `iceberg::Error` type. + /// ```toml + /// disallowed-types = [ + /// { path = "iceberg::Error", reason = "Please use `my_crate::IcebergError` instead." }, + /// ] + /// ``` pub fn backtrace(&self) -> &Backtrace { &self.backtrace }