From b44cd4e6eb46cebe5f0ea71b6d435127e469aff9 Mon Sep 17 00:00:00 2001 From: moxian Date: Sun, 30 Mar 2025 14:56:48 -0700 Subject: [PATCH] Better error message on failing to parse --verify-fn clap formats the FromStr::Err's arising from parsing the flags with the Display formatter. This is a very reasonable default but it also means it loses all the context, since anyhow::Error only prints the outermost error in Display. So any failure parsing/creating/loading the function is displayed to the user as simple "compiling and loading rust function", which is impossible to debug. Using the Debug formatting in impl FromStr for RustFunction helps work around this. --- src/dylib_flag.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dylib_flag.rs b/src/dylib_flag.rs index 229ea6d..1fca586 100644 --- a/src/dylib_flag.rs +++ b/src/dylib_flag.rs @@ -25,7 +25,8 @@ impl FromStr for RustFunction { type Err = anyhow::Error; fn from_str(s: &str) -> Result { - Self::compile(s).context("compiling and loading rust function") + Self::compile(s) + .map_err(|e| anyhow::format_err!("compiling and loading rust function: {:?}", e)) } }