wiggle GuestError: improve Display of InFunc, InDataField

This commit is contained in:
Pat Hickey
2021-03-23 22:03:25 -07:00
parent 6b2da3d299
commit 1151f630b8
2 changed files with 5 additions and 2 deletions

View File

@@ -139,10 +139,12 @@ impl witx::Bindgen for Rust<'_> {
) {
let rt = self.rt;
let wrap_err = |location: &str| {
let modulename = self.module.name.as_str();
let funcname = self.funcname;
quote! {
|e| {
#rt::GuestError::InFunc {
modulename: #modulename,
funcname: #funcname,
location: #location,
err: Box::new(#rt::GuestError::from(e)),

View File

@@ -19,14 +19,15 @@ pub enum GuestError {
BorrowCheckerOutOfHandles,
#[error("Slice length mismatch")]
SliceLengthsDiffer,
#[error("In func {funcname}:{location}:")]
#[error("In func {modulename}::{funcname} at {location}: {err}")]
InFunc {
modulename: &'static str,
funcname: &'static str,
location: &'static str,
#[source]
err: Box<GuestError>,
},
#[error("In data {typename}.{field}:")]
#[error("In data {typename}.{field}: {err}")]
InDataField {
typename: String,
field: String,