This bit of a hack but it's what we can do at the moment without changing up the internal errors.
To get more accurate error mappings we can try to parse the errno from error message string which may contain the errno from Rust when it is an std::io::Error before falling back to the current approach of switching on error.name.
This is a good first issue.
Hello! Ill grab this one.
@caspervonb hello! Is the example found here https://deno.land/[email protected]/wasi broken?
I found where this change needs to go, but I'm not able to successfully run this example, even with the unstable flag.
error: TS2322 [ERROR]: Type '{ get(key: string): string | undefined; set(key: string, value: string): void; delete(key: string): void; toObject(): { [index: string]: string; }; }' is not assignable to type '{ [key: string]: string | undefined; }'.
Property 'get' is incompatible with index signature.
Type '(key: string) => string | undefined' is not assignable to type 'string'.
env: Deno.env,
~~~
The expected type comes from property 'env' which is declared here on type 'ContextOptions'
env?: { [key: string]: string | undefined };
~~~
TS2322 [ERROR]: Type 'ImportValue' is not assignable to type 'Memory'.
Type 'number' is not assignable to type 'Memory'.
context.memory = context.exports.memory;
TS2349 [ERROR]: This expression is not callable.
No constituent of type 'ExportValue' is callable.
instance.exports._start();
TS2576 [ERROR]: Property 'exports' is a static member of type 'Module'
} else if (module.exports._initialize)
TS2349 [ERROR]: This expression is not callable.
No constituent of type 'ExportValue' is callable.
instance.exports._initialize();
Stricter WebAssembly definitions since a few releases ago, I should update that.
Something like this would work.
if (module.exports._start instanceof CallableFunction) {
instance.exports._start();
} else if (module.exports._initialize instanceof CallableFunction) {
instance.exports._initialize();
} else {
throw new Error("No entry point found");
}
Altho in this case, I think the tests should just be in JavaScript testing that the conversion is correct localized to the syscall function.
The upstream test suite doesn't enforce system conditions because in most cases it can't, the OS is really who decides what error it throws at us we just need to translate it.
Just to be a bit more explicit, said attempt at parsing would go in this catch block.
There is probably an up to date mapping from POSIX errno to WASI errno in wasi-libc or rust libstd.