mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix: add fsEvent notify::Error casts (#4488)
This commit is contained in:
parent
07fc95acee
commit
addfdc4cd0
2 changed files with 46 additions and 0 deletions
|
@ -14,6 +14,26 @@ unitTest({ perms: { read: false } }, function fsEventsPermissions() {
|
||||||
assert(thrown);
|
assert(thrown);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest({ perms: { read: true } }, function fsEventsInvalidPath() {
|
||||||
|
let thrown = false;
|
||||||
|
try {
|
||||||
|
Deno.fsEvents("non-existant.file");
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
if (Deno.build.os === "win") {
|
||||||
|
assert(
|
||||||
|
err.message.includes(
|
||||||
|
"Input watch path is neither a file nor a directory"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
assert(err instanceof Deno.errors.NotFound);
|
||||||
|
}
|
||||||
|
thrown = true;
|
||||||
|
}
|
||||||
|
assert(thrown);
|
||||||
|
});
|
||||||
|
|
||||||
async function getTwoEvents(
|
async function getTwoEvents(
|
||||||
iter: AsyncIterableIterator<Deno.FsEvent>
|
iter: AsyncIterableIterator<Deno.FsEvent>
|
||||||
): Promise<Deno.FsEvent[]> {
|
): Promise<Deno.FsEvent[]> {
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::import_map::ImportMapError;
|
||||||
use deno_core::ErrBox;
|
use deno_core::ErrBox;
|
||||||
use deno_core::ModuleResolutionError;
|
use deno_core::ModuleResolutionError;
|
||||||
use dlopen;
|
use dlopen;
|
||||||
|
use notify;
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use std;
|
use std;
|
||||||
|
@ -349,6 +350,30 @@ impl From<&dlopen::Error> for OpError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<notify::Error> for OpError {
|
||||||
|
fn from(error: notify::Error) -> Self {
|
||||||
|
OpError::from(&error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<¬ify::Error> for OpError {
|
||||||
|
fn from(error: ¬ify::Error) -> Self {
|
||||||
|
use notify::ErrorKind::*;
|
||||||
|
let kind = match error.kind {
|
||||||
|
Generic(_) => ErrorKind::Other,
|
||||||
|
Io(ref e) => return e.into(),
|
||||||
|
PathNotFound => ErrorKind::NotFound,
|
||||||
|
WatchNotFound => ErrorKind::NotFound,
|
||||||
|
InvalidConfig(_) => ErrorKind::InvalidData,
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
kind,
|
||||||
|
msg: error.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<ErrBox> for OpError {
|
impl From<ErrBox> for OpError {
|
||||||
fn from(error: ErrBox) -> Self {
|
fn from(error: ErrBox) -> Self {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -384,6 +409,7 @@ impl From<ErrBox> for OpError {
|
||||||
.map(|e| e.into())
|
.map(|e| e.into())
|
||||||
})
|
})
|
||||||
.or_else(|| error.downcast_ref::<dlopen::Error>().map(|e| e.into()))
|
.or_else(|| error.downcast_ref::<dlopen::Error>().map(|e| e.into()))
|
||||||
|
.or_else(|| error.downcast_ref::<notify::Error>().map(|e| e.into()))
|
||||||
.or_else(|| unix_error_kind(&error))
|
.or_else(|| unix_error_kind(&error))
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
panic!("Can't downcast {:?} to OpError", error);
|
panic!("Can't downcast {:?} to OpError", error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue