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

feat(runtime): give OS errors .code attributes #12591

Merged
merged 10 commits into from
Nov 4, 2021

Conversation

AaronO
Copy link
Contributor

@AaronO AaronO commented Oct 29, 2021

This adds .code attributes to errors returned by the op-layer, facilitating classifying OS errors and helping node-compat.

Similar to Node, these .code attributes are stringified names of unix ERRNOs, the mapping tables are generated by tools/codegen_error_codes.js and derived from libuv and rust's std internals

@AaronO AaronO requested a review from bartlomieju October 29, 2021 11:37
@bartlomieju
Copy link
Member

bartlomieju commented Oct 29, 2021

We should discuss this change in design meeting before landing it. Type definitions are not updated, and I'm not sure we want to always assign these codes to errors.

@piscisaureus
Copy link
Member

Non exhaustive first-pass. Might help with node-compat work

My suggestion would be:

  • Do the the error code lookup in Rust
  • Look at the system error code using std::io::Error::raw_os_error().
  • On unix you want to map like this:
     let code: &'static str = match e.raw_os_error() {
       libc::ENOENT { "ENOENT" },
       libc::EISDIR { "EISDIR" },
       // etc...
     };
    The error codes that might appear in node are defined in libuv.
  • On windows, use libuv's mapping table.

Non exhaustive first-pass. Might help with node-compat work
@AaronO AaronO force-pushed the feat/os-error-codes branch from dbbda0f to 87fbf9f Compare November 2, 2021 10:32
@AaronO
Copy link
Contributor Author

AaronO commented Nov 2, 2021

@bartlomieju @piscisaureus PTAL

Copy link
Member

@piscisaureus piscisaureus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please consider comments.

@AaronO AaronO self-assigned this Nov 4, 2021
@AaronO AaronO merged commit 44511e4 into denoland:main Nov 4, 2021
@AaronO AaronO deleted the feat/os-error-codes branch November 4, 2021 15:44
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