summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/js/tests/fs_events_test.ts20
-rw-r--r--cli/op_error.rs26
2 files changed, 46 insertions, 0 deletions
diff --git a/cli/js/tests/fs_events_test.ts b/cli/js/tests/fs_events_test.ts
index b1697971a..8494bf6af 100644
--- a/cli/js/tests/fs_events_test.ts
+++ b/cli/js/tests/fs_events_test.ts
@@ -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[]> {
diff --git a/cli/op_error.rs b/cli/op_error.rs
index bebfd2e72..3537d4b28 100644
--- a/cli/op_error.rs
+++ b/cli/op_error.rs
@@ -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);