summaryrefslogtreecommitdiff
path: root/ext/websocket/lib.rs
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-08-15 13:29:19 +0200
committerGitHub <noreply@github.com>2021-08-15 13:29:19 +0200
commit2ca454b402d48c1808f8233c5adedc11b714c63c (patch)
tree592f9e877e9b0ae92be80383ab723cc290e4b01e /ext/websocket/lib.rs
parent18ff6bb053d600c277613628a256fe5fdd4dda67 (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/websocket/lib.rs')
-rw-r--r--ext/websocket/lib.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs
index 40bcb7bc4..c75fa1742 100644
--- a/ext/websocket/lib.rs
+++ b/ext/websocket/lib.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-use deno_core::error::bad_resource_id;
use deno_core::error::invalid_hostname;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
@@ -272,8 +271,7 @@ where
let r = state
.borrow_mut()
.resource_table
- .get::<WsCancelResource>(cancel_rid)
- .ok_or_else(bad_resource_id)?;
+ .get::<WsCancelResource>(cancel_rid)?;
client
.or_cancel(r.0.to_owned())
.await
@@ -289,7 +287,7 @@ where
})?;
if let Some(cancel_rid) = args.cancel_handle {
- state.borrow_mut().resource_table.close(cancel_rid);
+ state.borrow_mut().resource_table.close(cancel_rid).ok();
}
let (ws_tx, ws_rx) = stream.split();
@@ -343,8 +341,7 @@ pub async fn op_ws_send(
let resource = state
.borrow_mut()
.resource_table
- .get::<WsStreamResource>(args.rid)
- .ok_or_else(bad_resource_id)?;
+ .get::<WsStreamResource>(args.rid)?;
resource.send(msg).await?;
Ok(())
}
@@ -374,8 +371,7 @@ pub async fn op_ws_close(
let resource = state
.borrow_mut()
.resource_table
- .get::<WsStreamResource>(rid)
- .ok_or_else(bad_resource_id)?;
+ .get::<WsStreamResource>(rid)?;
resource.send(msg).await?;
Ok(())
}
@@ -400,8 +396,7 @@ pub async fn op_ws_next_event(
let resource = state
.borrow_mut()
.resource_table
- .get::<WsStreamResource>(rid)
- .ok_or_else(bad_resource_id)?;
+ .get::<WsStreamResource>(rid)?;
let cancel = RcRef::map(&resource, |r| &r.cancel);
let val = resource.next_message(cancel).await?;