Skip to content

Improve error reporting #9

@Parzival-3141

Description

@Parzival-3141

Currently panics will only print an error message and abort. Unhandled errors are slightly better, printing the callback it bubbled up to as well.

This Sucks™, and is a drastically worse DX (developer experience) compared to the native ZX (zig experience).
In order to provide better stack traces for panics, we need a replacement for @returnAddress() and access to debug info. These features would have to be exposed by the Orca runtime.

@returnAddress() is not supported for the wasm-freestanding target and will always return 0. This limitation stems from the fact that the wasm spec doesn't define any way for a module to natively gather information about it's execution environment, including debug symbols. The information can only be accessed by querying the host runtime.

For panics this is fine, we can simply modify our custom panic handler. Error return traces however, may not be possible to implement in userspace. The implementation for @errorReturnTrace() uses a stack which is populated via a builtin in std invoked whenever a function returns an error at runtime. So upon catching an error, the stack will be full of zeroes due to @returnAddress(), which (unlike with panic) we can't replace it since it's called in the stdlib builtin.

So AFAICT, our options are to either:

  • Include and compile a patched stdlib (ew).
  • Submit a proposal/patch upstream to allow overriding runtime invocations of @returnAddress() or std.builtin.returnError() for wasm targets in Debug mode.

See also:
ziglang/zig#11946
https://github.com/ziglang/zig/blob/3974540e5a1226acf9f30b43dc5a7f4fa1a16041/src/target.zig#L282-L294
https://reviews.llvm.org/D62210?id=200619

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions