What is the usual idiom for error handling in the wizer initialization function in go? panic() isn't supported, nor is os.Exit(1).
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.
aha, compiling the go with tinygo --panic=trap should do it, thanks (though if we used panic for anything else, that might be annoying)
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> {
...
}
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
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.
ah okay, that's a bummer. seems like it and/or a wasm trap
intrinsic should really be added to go
Last updated: Dec 23 2024 at 12:05 UTC