summaryrefslogtreecommitdiff
path: root/cli/ops/io.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-09-10 06:59:40 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-09-10 00:59:40 -0400
commit2a83327a21e83180a21afd428b11aa03e3080346 (patch)
tree670ac1ca0644d3b082d1baffc8514ad9d9fe3ef4 /cli/ops/io.rs
parent377966764636350c524b526da50c055243ab3005 (diff)
fix: replace bad rid panics with errors (#2870)
Diffstat (limited to 'cli/ops/io.rs')
-rw-r--r--cli/ops/io.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/cli/ops/io.rs b/cli/ops/io.rs
index 610238942..8b8520c35 100644
--- a/cli/ops/io.rs
+++ b/cli/ops/io.rs
@@ -1,6 +1,7 @@
use super::dispatch_minimal::MinimalOp;
use crate::deno_error;
use crate::resources;
+use crate::tokio_read;
use crate::tokio_write;
use deno::ErrBox;
use deno::PinnedBuf;
@@ -14,10 +15,11 @@ pub fn op_read(rid: i32, zero_copy: Option<PinnedBuf>) -> Box<MinimalOp> {
}
Some(buf) => buf,
};
+
match resources::lookup(rid as u32) {
- None => Box::new(futures::future::err(deno_error::bad_resource())),
- Some(resource) => Box::new(
- tokio::io::read(resource, zero_copy)
+ Err(e) => Box::new(futures::future::err(e)),
+ Ok(resource) => Box::new(
+ tokio_read::read(resource, zero_copy)
.map_err(ErrBox::from)
.and_then(move |(_resource, _buf, nread)| Ok(nread as i32)),
),
@@ -32,9 +34,10 @@ pub fn op_write(rid: i32, zero_copy: Option<PinnedBuf>) -> Box<MinimalOp> {
}
Some(buf) => buf,
};
+
match resources::lookup(rid as u32) {
- None => Box::new(futures::future::err(deno_error::bad_resource())),
- Some(resource) => Box::new(
+ Err(e) => Box::new(futures::future::err(e)),
+ Ok(resource) => Box::new(
tokio_write::write(resource, zero_copy)
.map_err(ErrBox::from)
.and_then(move |(_resource, _buf, nwritten)| Ok(nwritten as i32)),