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: add WouldBlock error #17339

Merged
merged 10 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/tests/unit/error_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Deno.test("Errors work", () => {
assert(new Deno.errors.InvalidData("msg") instanceof Error);
assert(new Deno.errors.TimedOut("msg") instanceof Error);
assert(new Deno.errors.Interrupted("msg") instanceof Error);
assert(new Deno.errors.WouldBlock("msg") instanceof Error);
assert(new Deno.errors.WriteZero("msg") instanceof Error);
assert(new Deno.errors.UnexpectedEof("msg") instanceof Error);
assert(new Deno.errors.BadResource("msg") instanceof Error);
Expand Down
12 changes: 9 additions & 3 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ declare namespace Deno {
*
* @category Errors */
export class Interrupted extends Error {}
/**
* Raised when the underlying operating system would need to block to
* complete but an asynchronous (non-blocking) API is used.
*
* @category Errors */
export class WouldBlock extends Error {}
/**
* Raised when expecting to write to a IO buffer resulted in zero bytes
* being written.
Expand Down Expand Up @@ -4377,7 +4383,7 @@ declare namespace Deno {
* const status = await Deno.permissions.query({ name: "read", path: "/etc" });
* console.log(status.state);
* ```
*
*
* ```ts
* const status = Deno.permissions.querySync({ name: "read", path: "/etc" });
* console.log(status.state);
Expand All @@ -4391,7 +4397,7 @@ declare namespace Deno {
* const status = await Deno.permissions.revoke({ name: "run" });
* assert(status.state !== "granted")
* ```
*
*
* ```ts
* import { assert } from "https://deno.land/std/testing/asserts.ts";
*
Expand All @@ -4409,7 +4415,7 @@ declare namespace Deno {
* console.log("'env' permission is denied.");
* }
* ```
*
*
* ```ts
* const status = Deno.permissions.requestSync({ name: "env" });
* if (status.state === "granted") {
Expand Down
1 change: 1 addition & 0 deletions core/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn get_io_error_code(err: &std::io::Error) -> &'static str {
// ErrorKind::ExecutableFileBusy => "ETXTBSY",
// ErrorKind::CrossesDevices => "EXDEV",
ErrorKind::PermissionDenied => "EACCES", // NOTE: Collides with EPERM ...
ErrorKind::WouldBlock => "EWOULDBLOCK", // NOTE: Collides with EAGAIN ...
_ => "",
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn get_io_error_class(error: &io::Error) -> &'static str {
WriteZero => "WriteZero",
UnexpectedEof => "UnexpectedEof",
Other => "Error",
WouldBlock => unreachable!(),
WouldBlock => "WouldBlock",
// Non-exhaustive enum - might add new variants
// in the future
_ => "Error",
Expand Down
8 changes: 8 additions & 0 deletions runtime/js/01_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class WriteZero extends Error {
}
}

class WouldBlock extends Error {
constructor(msg) {
super(msg);
this.name = "WouldBlock";
}
}

class UnexpectedEof extends Error {
constructor(msg) {
super(msg);
Expand Down Expand Up @@ -139,6 +146,7 @@ const errors = {
TimedOut,
Interrupted,
WriteZero,
WouldBlock,
UnexpectedEof,
BadResource,
Http,
Expand Down
1 change: 1 addition & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ function registerErrors() {
core.registerErrorClass("InvalidData", errors.InvalidData);
core.registerErrorClass("TimedOut", errors.TimedOut);
core.registerErrorClass("Interrupted", errors.Interrupted);
core.registerErrorClass("WouldBlock", errors.WouldBlock);
core.registerErrorClass("WriteZero", errors.WriteZero);
core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof);
core.registerErrorClass("BadResource", errors.BadResource);
Expand Down