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

Add wasi.Errno type implementing the error interface #64

Closed
achille-roussel opened this issue Dec 7, 2021 · 2 comments · Fixed by #72
Closed

Add wasi.Errno type implementing the error interface #64

achille-roussel opened this issue Dec 7, 2021 · 2 comments · Fixed by #72

Comments

@achille-roussel
Copy link
Collaborator

achille-roussel commented Dec 7, 2021

Hello,

I'm opening this issue to discuss changing the way error codes in https://github.com/tetratelabs/wazero/blob/main/wasi/errno.go are represented.

Instead of being simple uint32, how about making the a type implementing the error interface. This would be useful to return error codes from custom implementations of the wasi.FS and wasi.File interfaces, which are otherwise converted to the generic EIO code in functions like fd_read or fd_write, for example https://github.com/tetratelabs/wazero/blob/main/wasi/wasi.go#L258

The Errno type would be defined as such:

type Errno uint32

func (e Errno) Error() string { return fmt.Sprintf("wasi.Errno(%d)", uint32(e)) }

The error codes declared in errno.go would be declared as constants of the Errno type:

const (
  ESUCCESS Errno = 0
  ...
)

The signature of functions like fd_read can then be modified to return an Errno value instead of a plain uint32. I believe this should remain compatible with the current implementation since the underlying type remains unchanged, the use of reflection to discover the function signature would keep seeing return values of kind reflect.Uint32.

Let me know if you have any concerns about it or I have overlooked implementation details, I can send a pull request if we agree the change would be useful.

@codefromthecrypt
Copy link
Contributor

unless there is some implicit overhead added when using type Errno uint32 vs plain uint32, SGTM (especially using const)

@mathetake do you see any other things we should consider here?

aside: this file is also due some backfilling of docs similar to this regardless https://github.com/tetratelabs/wazero/pull/61/files

@mathetake
Copy link
Member

mathetake commented Dec 8, 2021

SGTM as well, thanks you @achille-roussel. Note that WASI code is not written by me but a contributor when this project was in hiatus period, so in anyway the WASI package needs refactoring! 🔥

I would really appreciate it if you could send a PR! Thanks in advance! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants