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

fix(runtime): Extract error code for all OS error variants #17958

Merged
merged 5 commits into from
Mar 19, 2023
Merged

fix(runtime): Extract error code for all OS error variants #17958

merged 5 commits into from
Mar 19, 2023

Conversation

kamilogorek
Copy link
Contributor

@kamilogorek kamilogorek commented Feb 26, 2023

Changes in #17719 made all read_file methods return ErrorData::Custom instead of the original ErrorData::Os.
This is correct and unified behavior, however problematic at the same time, as get_io_error_code is not implemented for all possible ErrorKind variants.

In order to work around this, the newly created error is wrapped in anyhow::Error and the original std::io::Error is provided as its context. This makes a downcasting in get_error_code successful and allows get_os_error_code to be used for code extraction instead of problematic get_io_error_code.

File in question: https://github.com/denoland/deno/blob/main/core/error_codes.rs

It also changes error format from (err, desc to err: desc).


Error: Is a directory (os error 21), readfile 'test'
Error: Is a directory (os error 21): readfile 'test'


NotFound: No such file or directory (os error 2), readfile 'tes'
NotFound: No such file or directory (os error 2): readfile 'tes'

Note that on Windows, EISDIR is reported as ENOENT due to Deno using libuv mappings (Windows code for this is 267) - https://github.com/libuv/libuv/blob/master/src/win/error.c

Fixes #17950

Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

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

LGTM, but needs rebase.

@aapoalas aapoalas enabled auto-merge (squash) March 14, 2023 19:31
auto-merge was automatically disabled March 14, 2023 20:30

Head branch was pushed to by a user without write access

@kamilogorek
Copy link
Contributor Author

Done. All green!

@aapoalas aapoalas enabled auto-merge (squash) March 15, 2023 05:45
@aapoalas
Copy link
Collaborator

Thank you once again, and nice work!

@bartlomieju
Copy link
Member

@aapoalas please land at first convenience

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.

Deno 1.31.1 Calling Deno.readFile will not throw with EISDIR error code if file is a directory
3 participants