Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More descriptive errors (file and line, what it was trying to do) #740

Closed
VorpalBlade opened this issue Jul 16, 2024 · 4 comments
Closed

Comments

@VorpalBlade
Copy link
Contributor

Consider this rune example (involving some custom types):

    let sysinfo = sysinfo::SysInfo::new();
    println!("1: Configuring for host {} (distro: {})", sysinfo.host_name()?, sysinfo.os_id());
    println!("2: Configuring for host {} (distro: {})", sysinfo.host_name(), sysinfo.os_id());

sysinfo.host_name returns a Option<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:

1: Configuring for host athena (distro: arch)
Error: Got error while executing phase phase_system_discovery

Caused by:
    Missing function with hash `0x811b62957ea9d9f9`

I don't see a way to extract a more useful error message from this. I would like one or more of:

  • Which file and line the error happened at.
  • What function name it was trying to call (I was trying to debug why println! didn't work, since dbg() did, which was completely the wrong place to be looking).

Anything to make this error more human readable.

Even the at or chain members on VmError contain nothing useful when I print them (and VmErrorAt appears to be a private type as well according to the docs, since it isn't a clickable link):

Error: Got error while executing phase phase_system_discovery
  At VmErrorAt { index: 0, kind: MissingFunction { hash: 0x811b62957ea9d9f9 } }
  Chain: []
@VorpalBlade
Copy link
Contributor Author

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.

@udoprog
Copy link
Collaborator

udoprog commented Jul 16, 2024

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).

@VorpalBlade
Copy link
Contributor Author

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).

@VorpalBlade
Copy link
Contributor Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants