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:
parent
dc66fdc11e
commit
8b5be962f5
6 changed files with 21 additions and 4 deletions
|
@ -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);
|
||||||
|
|
6
cli/tsc/dts/lib.deno.ns.d.ts
vendored
6
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -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.
|
||||||
|
|
|
@ -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 ...
|
||||||
_ => "",
|
_ => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue