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

Report crypto error cause along with $errno #13

Closed
wants to merge 1 commit into from

Conversation

ueno
Copy link
Contributor

@ueno ueno commented Mar 15, 2020

Related to #6.

Rather than using own error codes for the crypto operations, this makes the functions return the cause of failure ($crypto_error_cause) along with the normal $errno. That way, the caller can handle e.g., $errno.nosys in a similar manner to the rest of WASI hostcalls.

To represent specific error cause for the crypto operations, this
introduces the $crypto_erorr_cause type, which shall be reported along
with the normal $errno, so that the caller can still handle common
errnos e.g., $errno.nosys in a similar manner to the rest of WASI
hostcalls.
@jedisct1
Copy link
Member

Mmm... returning two error codes is going to be a little bit awkward to handle and may not play well with wiggle.

How would you recommend returning module-specific errors, while some of these errors may overlap with standard errors @sunfishcode ?

Maybe submodules could share the standard errno type, with values having the high bit set?

@sunfishcode
Copy link
Member

My suggestion is to try avoiding $errno altogether for now. Staying consistent with things like ENOSYS in non-crypto APIs is lower priority than designing a good API for crypto.

A few background thoughts:

It's valuable in a crypto API to think through the possible failure modes, and how you want applications to handle them. Defining your own error codes is one way to push yourself to think this through. In the particular case of ENOSYS, think about whether what you really have is optional functionality and optional imports would be a better fit, or essential functionality, where it makes sense to just require implementations to implement it if they implement WASI-crypto at all, and maybe don't give them the option of returning ENOSYS. I'm oversimplifying, but my broader idea is just: think about what makes sense for your API first.

As a separate thought, $errno errors are mostly relevant at the scope of code which does approximately one system call. Once you zoom out to code that does multiple system calls, even something like ENOSYS becomes mostly meaningless. At the scope of code which is calling functions in both the more POSIX-style parts of WASI and WASI-crypto, a single errno-style error code won't carry relevant information. To illustrate, picture a function call that does some I/O and some crypto, and uses $errno as its return type. If you call it and it returns EINVAL or ENOSYS or most any other errno code, you can't do a lot with that information except treat it as a generic failure, because you don't know which function failed or how it failed. Consequently, I don't expect it will be important to have a single errno type which spans all WASI APIs.

@ueno
Copy link
Contributor Author

ueno commented Mar 20, 2020

OK, let's close this and use the $crypto_errno exclusively.

@ueno ueno closed this Mar 20, 2020
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 this pull request may close these issues.

3 participants