diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-08-15 13:29:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 13:29:19 +0200 |
commit | 2ca454b402d48c1808f8233c5adedc11b714c63c (patch) | |
tree | 592f9e877e9b0ae92be80383ab723cc290e4b01e /ext/fetch | |
parent | 18ff6bb053d600c277613628a256fe5fdd4dda67 (diff) |
refactor(ops): return BadResource errors in ResourceTable calls (#11710)
* refactor(ops): return BadResource errors in ResourceTable calls
Instead of relying on callers to map Options to Results via `.ok_or_else(bad_resource_id)` at over 176 different call sites ...
Diffstat (limited to 'ext/fetch')
-rw-r--r-- | ext/fetch/lib.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index e89df470a..eb2fed683 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -1,7 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use data_url::DataUrl; -use deno_core::error::bad_resource_id; use deno_core::error::null_opbuf; use deno_core::error::type_error; use deno_core::error::AnyError; @@ -163,10 +162,7 @@ where FP: FetchPermissions + 'static, { let client = if let Some(rid) = args.client_rid { - let r = state - .resource_table - .get::<HttpClientResource>(rid) - .ok_or_else(bad_resource_id)?; + let r = state.resource_table.get::<HttpClientResource>(rid)?; r.client.clone() } else { let client = state.borrow::<reqwest::Client>(); @@ -345,8 +341,7 @@ pub async fn op_fetch_send( let request = state .borrow_mut() .resource_table - .take::<FetchRequestResource>(rid) - .ok_or_else(bad_resource_id)?; + .take::<FetchRequestResource>(rid)?; let request = Rc::try_unwrap(request) .ok() @@ -402,8 +397,7 @@ pub async fn op_fetch_request_write( let resource = state .borrow() .resource_table - .get::<FetchRequestBodyResource>(rid) - .ok_or_else(bad_resource_id)?; + .get::<FetchRequestBodyResource>(rid)?; let body = RcRef::map(&resource, |r| &r.body).borrow_mut().await; let cancel = RcRef::map(resource, |r| &r.cancel); body.send(Ok(buf)).or_cancel(cancel).await?.map_err(|_| { @@ -423,8 +417,7 @@ pub async fn op_fetch_response_read( let resource = state .borrow() .resource_table - .get::<FetchResponseBodyResource>(rid) - .ok_or_else(bad_resource_id)?; + .get::<FetchResponseBodyResource>(rid)?; let mut reader = RcRef::map(&resource, |r| &r.reader).borrow_mut().await; let cancel = RcRef::map(resource, |r| &r.cancel); let mut buf = data.clone(); |