Stream: general

Topic: wizer and errors


view this post on Zulip Dan Kegel (Jul 20 2021 at 15:06):

What is the usual idiom for error handling in the wizer initialization function in go? panic() isn't supported, nor is os.Exit(1).

view this post on Zulip bjorn3 (Jul 20 2021 at 16:12):

I did assume a wasm trap would work. I can't find how to directly emit one in go. In rust it would be std::process::abort. You could try to read/write from the address 0xffff_ffff. Assuming that the go compiler doesn't exploit ub and you don't allocate 2^32-1 bytes of memory this will cause a trap due to accessing unmapped memory.

view this post on Zulip Dan Kegel (Jul 20 2021 at 17:09):

aha, compiling the go with tinygo --panic=trap should do it, thanks (though if we used panic for anything else, that might be annoying)

view this post on Zulip fitzgen (he/him) (Aug 02 2021 at 17:08):

In general, I would do something like (apologies for the pseudocode, I don't know go) this:

fn wizer_initialize() {
    if let Err(e) = try_init() {
        fprintf(stderr, "error: %s\n", e);
        abort();
    }
}

fn try_init() -> Result<(), Error> {
    ...
}

view this post on Zulip fitzgen (he/him) (Aug 02 2021 at 17:10):

using explicit fallibility with try_init should hopefully avoid configuring the build to do anything different with panics than you otherwise would, so it is hopefully minimally invasive

view this post on Zulip bjorn3 (Aug 02 2021 at 20:11):

I believe the problem was getting the abort() in go. I don't think go has any such function, so panic=trap is the only possible option I think.

view this post on Zulip fitzgen (he/him) (Aug 02 2021 at 22:35):

ah okay, that's a bummer. seems like it and/or a wasm trap intrinsic should really be added to go


Last updated: Oct 23 2024 at 20:03 UTC