summaryrefslogtreecommitdiff
path: root/cli/ops/fs_events.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-02-23 14:51:29 -0500
committerGitHub <noreply@github.com>2020-02-23 14:51:29 -0500
commit4e1abb4f3a1fbdac25b1e7db0588572e4d5a6579 (patch)
tree644ace7dc1acac7b09bfab037e0ca589fa11987b /cli/ops/fs_events.rs
parent45eb2f9b37c2c7498c58eb45f76667aaa4a7d731 (diff)
refactor: use OpError instead of ErrBox for errors in ops (#4058)
To better reflect changes in error types in JS from #3662 this PR changes default error type used in ops from "ErrBox" to "OpError". "OpError" is a type that can be sent over to JSON; it has all information needed to construct error in JavaScript. That made "GetErrorKind" trait useless and so it was removed altogether. To provide compatibility with previous use of "ErrBox" an implementation of "From<ErrBox> for OpError" was added, however, it is an escape hatch and ops implementors should strive to use "OpError" directly.
Diffstat (limited to 'cli/ops/fs_events.rs')
-rw-r--r--cli/ops/fs_events.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/cli/ops/fs_events.rs b/cli/ops/fs_events.rs
index 471556b5a..3b4c9b9e5 100644
--- a/cli/ops/fs_events.rs
+++ b/cli/ops/fs_events.rs
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
-use crate::deno_error::bad_resource;
+use crate::op_error::OpError;
use crate::ops::json_op;
use crate::state::State;
use deno_core::*;
@@ -70,7 +70,7 @@ pub fn op_fs_events_open(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
#[derive(Deserialize)]
struct OpenArgs {
recursive: bool,
@@ -84,7 +84,8 @@ pub fn op_fs_events_open(
let res2 = res.map(FsEvent::from).map_err(ErrBox::from);
let mut sender = sender.lock().unwrap();
futures::executor::block_on(sender.send(res2)).expect("fs events error");
- })?;
+ })
+ .map_err(ErrBox::from)?;
let recursive_mode = if args.recursive {
RecursiveMode::Recursive
} else {
@@ -92,7 +93,7 @@ pub fn op_fs_events_open(
};
for path in &args.paths {
state.check_read(&PathBuf::from(path))?;
- watcher.watch(path, recursive_mode)?;
+ watcher.watch(path, recursive_mode).map_err(ErrBox::from)?;
}
let resource = FsEventsResource { watcher, receiver };
let table = &mut state.borrow_mut().resource_table;
@@ -104,7 +105,7 @@ pub fn op_fs_events_poll(
state: &State,
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
-) -> Result<JsonOp, ErrBox> {
+) -> Result<JsonOp, OpError> {
#[derive(Deserialize)]
struct PollArgs {
rid: u32,
@@ -115,13 +116,13 @@ pub fn op_fs_events_poll(
let resource_table = &mut state.borrow_mut().resource_table;
let watcher = resource_table
.get_mut::<FsEventsResource>(rid)
- .ok_or_else(bad_resource)?;
+ .ok_or_else(OpError::bad_resource)?;
watcher
.receiver
.poll_recv(cx)
.map(|maybe_result| match maybe_result {
Some(Ok(value)) => Ok(json!({ "value": value, "done": false })),
- Some(Err(err)) => Err(err),
+ Some(Err(err)) => Err(OpError::from(err)),
None => Ok(json!({ "done": true })),
})
});