Skip to content

Commit

Permalink
Include the whole error message in errors from Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 29, 2024
1 parent d093ce3 commit 7c29f83
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions taskchampion/lib/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use crate::string::RustString;

pub(crate) fn err_to_ruststring(e: impl std::string::ToString) -> RustString<'static> {
RustString::from(e.to_string())
pub(crate) fn err_to_ruststring(e: anyhow::Error) -> RustString<'static> {
// The default `to_string` representation of `anyhow::Error` only shows the "outermost"
// context, e.g., "Could not connect to server", and omits the juicy details about what
// actually went wrong. So, join all of those contexts with `: ` for presentation to the C++
// layer.
let entire_msg = e
.chain()
.skip(1)
.fold(e.to_string(), |a, b| format!("{}: {}", a, b));
RustString::from(entire_msg)
}

/// An implementation of Vec::into_raw_parts, which is still unstable. Returns ptr, len, cap.
Expand Down

0 comments on commit 7c29f83

Please sign in to comment.