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.
This commit is contained in:
moxian 2025-03-30 14:56:48 -07:00 committed by nora
parent 92aec21748
commit b44cd4e6eb

View file

@ -25,7 +25,8 @@ impl FromStr for RustFunction {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::compile(s).context("compiling and loading rust function")
Self::compile(s)
.map_err(|e| anyhow::format_err!("compiling and loading rust function: {:?}", e))
}
}