Closed VorpalBlade closed 3 months ago
first_location
is also useless, another private type, and it appears to print a bunch of byte code with Debug, and doesn't implement Display.
To convert an error into one which is more descriptive you use the associated emit
methods. If you want to capture it into a string, you can use a buffer like what's being done in rune-wasm
here:
https://github.com/rune-rs/rune/blob/main/crates/rune-wasm/src/lib.rs#L269
https://github.com/rune-rs/rune/blob/main/crates/rune-wasm/src/lib.rs#L301
To explain, detailed diagnostics has a memory overhead. To emit it you need to provide the context that was used to compile the program, all loaded sources, and the compiled unit (with debug info).
Thank you, I propose adding some cross references to the docs for VmError
about this. In fact I'll make a PR later today for it.
Discoverability when trying to solve an issue is a probkem in the rustdoc of many large Rust projects (not only Rune, I have struggled with clap and bpaf before for example). Part of that is due to the sub-par search function of rustdoc (only matching names of types/functions).
Actually, looking at it again, I'm not sure how I missed the emit
method on the VmError
type. Don't think there is much to improve (apart from my own reading comprehension).
Consider this rune example (involving some custom types):
sysinfo.host_name
returns aOption<String>
. The first print works, the second doesn't, since Option cannot be formatted like this.The issue however is that of the error message:
I don't see a way to extract a more useful error message from this. I would like one or more of:
println!
didn't work, sincedbg()
did, which was completely the wrong place to be looking).Anything to make this error more human readable.
Even the
at
orchain
members onVmError
contain nothing useful when I print them (andVmErrorAt
appears to be a private type as well according to the docs, since it isn't a clickable link):