1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-12 00:54:02 -05:00

fix: add WouldBlock error (#17339)

This commit is contained in:
Leo Kettmeir 2023-02-12 23:14:33 +01:00 committed by GitHub
parent dc66fdc11e
commit 8b5be962f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 4 deletions

View file

@ -15,6 +15,7 @@ Deno.test("Errors work", () => {
assert(new Deno.errors.InvalidData("msg") instanceof Error); assert(new Deno.errors.InvalidData("msg") instanceof Error);
assert(new Deno.errors.TimedOut("msg") instanceof Error); assert(new Deno.errors.TimedOut("msg") instanceof Error);
assert(new Deno.errors.Interrupted("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.WriteZero("msg") instanceof Error);
assert(new Deno.errors.UnexpectedEof("msg") instanceof Error); assert(new Deno.errors.UnexpectedEof("msg") instanceof Error);
assert(new Deno.errors.BadResource("msg") instanceof Error); assert(new Deno.errors.BadResource("msg") instanceof Error);

View file

@ -219,6 +219,12 @@ declare namespace Deno {
* *
* @category Errors */ * @category Errors */
export class Interrupted extends Error {} 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 * Raised when expecting to write to a IO buffer resulted in zero bytes
* being written. * being written.

View file

@ -56,6 +56,7 @@ fn get_io_error_code(err: &std::io::Error) -> &'static str {
// ErrorKind::ExecutableFileBusy => "ETXTBSY", // ErrorKind::ExecutableFileBusy => "ETXTBSY",
// ErrorKind::CrossesDevices => "EXDEV", // ErrorKind::CrossesDevices => "EXDEV",
ErrorKind::PermissionDenied => "EACCES", // NOTE: Collides with EPERM ... ErrorKind::PermissionDenied => "EACCES", // NOTE: Collides with EPERM ...
ErrorKind::WouldBlock => "EWOULDBLOCK", // NOTE: Collides with EAGAIN ...
_ => "", _ => "",
} }
} }

View file

@ -58,7 +58,7 @@ fn get_io_error_class(error: &io::Error) -> &'static str {
WriteZero => "WriteZero", WriteZero => "WriteZero",
UnexpectedEof => "UnexpectedEof", UnexpectedEof => "UnexpectedEof",
Other => "Error", Other => "Error",
WouldBlock => unreachable!(), WouldBlock => "WouldBlock",
// Non-exhaustive enum - might add new variants // Non-exhaustive enum - might add new variants
// in the future // in the future
_ => "Error", _ => "Error",

View file

@ -96,6 +96,13 @@ class WriteZero extends Error {
} }
} }
class WouldBlock extends Error {
constructor(msg) {
super(msg);
this.name = "WouldBlock";
}
}
class UnexpectedEof extends Error { class UnexpectedEof extends Error {
constructor(msg) { constructor(msg) {
super(msg); super(msg);
@ -139,6 +146,7 @@ const errors = {
TimedOut, TimedOut,
Interrupted, Interrupted,
WriteZero, WriteZero,
WouldBlock,
UnexpectedEof, UnexpectedEof,
BadResource, BadResource,
Http, Http,

View file

@ -265,6 +265,7 @@ function registerErrors() {
core.registerErrorClass("InvalidData", errors.InvalidData); core.registerErrorClass("InvalidData", errors.InvalidData);
core.registerErrorClass("TimedOut", errors.TimedOut); core.registerErrorClass("TimedOut", errors.TimedOut);
core.registerErrorClass("Interrupted", errors.Interrupted); core.registerErrorClass("Interrupted", errors.Interrupted);
core.registerErrorClass("WouldBlock", errors.WouldBlock);
core.registerErrorClass("WriteZero", errors.WriteZero); core.registerErrorClass("WriteZero", errors.WriteZero);
core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof); core.registerErrorClass("UnexpectedEof", errors.UnexpectedEof);
core.registerErrorClass("BadResource", errors.BadResource); core.registerErrorClass("BadResource", errors.BadResource);