Skip to content

Commit

Permalink
fix(ext/websocket): don't panic on bad resource id (#21431)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Dec 11, 2023
1 parent 5e24e28 commit 0bee37a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ext/websocket/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,19 +719,19 @@ pub async fn op_ws_close(
pub fn op_ws_get_buffer(
state: &mut OpState,
#[smi] rid: ResourceId,
) -> ToJsBuffer {
let resource = state.resource_table.get::<ServerWebSocket>(rid).unwrap();
resource.buffer.take().unwrap().into()
) -> Result<ToJsBuffer, AnyError> {
let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
Ok(resource.buffer.take().unwrap().into())
}

#[op2]
#[string]
pub fn op_ws_get_buffer_as_string(
state: &mut OpState,
#[smi] rid: ResourceId,
) -> String {
let resource = state.resource_table.get::<ServerWebSocket>(rid).unwrap();
resource.string.take().unwrap()
) -> Result<String, AnyError> {
let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
Ok(resource.string.take().unwrap())
}

#[op2]
Expand Down

0 comments on commit 0bee37a

Please sign in to comment.