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

Try to parse error messages to get an accurate error code for std/wasi #7626

Open
caspervonb opened this issue Sep 22, 2020 · 5 comments
Open

Try to parse error messages to get an accurate error code for std/wasi #7626

caspervonb opened this issue Sep 22, 2020 · 5 comments

Comments

@caspervonb
Copy link
Contributor

@caspervonb caspervonb commented Sep 22, 2020

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.

@caspervonb caspervonb changed the title Try to parse strings to get an accurate error code for std/wasi Try to parse error messages to get an accurate error code for std/wasi Sep 26, 2020
@JayHelton
Copy link
Contributor

@JayHelton JayHelton commented Oct 2, 2020

Hello! Ill grab this one.

@JayHelton
Copy link
Contributor

@JayHelton JayHelton commented Oct 3, 2020

@caspervonb hello! Is the example found here https://deno.land/std@0.72.0/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();

@caspervonb
Copy link
Contributor Author

@caspervonb caspervonb commented Oct 3, 2020

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");
}
@caspervonb
Copy link
Contributor Author

@caspervonb caspervonb commented Oct 3, 2020

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.

@caspervonb
Copy link
Contributor Author

@caspervonb caspervonb commented Oct 3, 2020

Just to be a bit more explicit, said attempt at parsing would go in this catch block.

function syscall<T extends CallableFunction>(target: T) {
return function (...args: unknown[]) {
try {
return target(...args);
} catch (err) {
switch (err.name) {
case "NotFound":

There is probably an up to date mapping from POSIX errno to WASI errno in wasi-libc or rust libstd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.