From 2a83327a21e83180a21afd428b11aa03e3080346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 10 Sep 2019 06:59:40 +0200 Subject: fix: replace bad rid panics with errors (#2870) --- cli/ops/files.rs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'cli/ops/files.rs') diff --git a/cli/ops/files.rs b/cli/ops/files.rs index 4afe00fc0..01abff3a9 100644 --- a/cli/ops/files.rs +++ b/cli/ops/files.rs @@ -1,6 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; -use crate::deno_error; use crate::fs as deno_fs; use crate::resources; use crate::state::ThreadSafeState; @@ -104,13 +103,9 @@ pub fn op_close( ) -> Result { let args: CloseArgs = serde_json::from_value(args)?; - match resources::lookup(args.rid as u32) { - None => Err(deno_error::bad_resource()), - Some(resource) => { - resource.close(); - Ok(JsonOp::Sync(json!({}))) - } - } + let resource = resources::lookup(args.rid as u32)?; + resource.close(); + Ok(JsonOp::Sync(json!({}))) } #[derive(Deserialize)] @@ -129,17 +124,13 @@ pub fn op_seek( ) -> Result { let args: SeekArgs = serde_json::from_value(args)?; - match resources::lookup(args.rid as u32) { - None => Err(deno_error::bad_resource()), - Some(resource) => { - let op = resources::seek(resource, args.offset, args.whence as u32) - .and_then(move |_| futures::future::ok(json!({}))); - if args.promise_id.is_none() { - let buf = op.wait()?; - Ok(JsonOp::Sync(buf)) - } else { - Ok(JsonOp::Async(Box::new(op))) - } - } + let resource = resources::lookup(args.rid as u32)?; + let op = resources::seek(resource, args.offset, args.whence as u32) + .and_then(move |_| futures::future::ok(json!({}))); + if args.promise_id.is_none() { + let buf = op.wait()?; + Ok(JsonOp::Sync(buf)) + } else { + Ok(JsonOp::Async(Box::new(op))) } } -- cgit v1.2.3