1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix: add fsEvent notify::Error casts (#4488)

This commit is contained in:
Kevin (Kun) "Kassimo" Qian 2020-03-24 20:50:51 -07:00 committed by GitHub
parent 07fc95acee
commit addfdc4cd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View file

@ -14,6 +14,26 @@ unitTest({ perms: { read: false } }, function fsEventsPermissions() {
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(
iter: AsyncIterableIterator<Deno.FsEvent>
): Promise<Deno.FsEvent[]> {

View file

@ -18,6 +18,7 @@ use crate::import_map::ImportMapError;
use deno_core::ErrBox;
use deno_core::ModuleResolutionError;
use dlopen;
use notify;
use reqwest;
use rustyline::error::ReadlineError;
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<&notify::Error> for OpError {
fn from(error: &notify::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 {
fn from(error: ErrBox) -> Self {
#[cfg(unix)]
@ -384,6 +409,7 @@ impl From<ErrBox> for OpError {
.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))
.unwrap_or_else(|| {
panic!("Can't downcast {:?} to OpError", error);