summaryrefslogtreecommitdiff
path: root/ext/net
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-09-27 16:07:20 +0200
committerGitHub <noreply@github.com>2024-09-27 14:07:20 +0000
commit3134abefa462ead8bb8e2e4aa8a5b57910f3d430 (patch)
tree0f01cca8ca91ea6fb06347f17a77091259749c28 /ext/net
parent88a4f8dd97704b8905d05def949b137a75286b18 (diff)
BREAKING(ext/net): improved error code accuracy (#25383)
Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/net')
-rw-r--r--ext/net/ops.rs1
-rw-r--r--ext/net/ops_tls.rs7
-rw-r--r--ext/net/raw.rs10
3 files changed, 8 insertions, 10 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index f2735eda9..5248493f4 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -69,7 +69,6 @@ impl From<SocketAddr> for IpAddr {
}
pub(crate) fn accept_err(e: std::io::Error) -> AnyError {
- // FIXME(bartlomieju): compatibility with current JS implementation
if let std::io::ErrorKind::Interrupted = e.kind() {
bad_resource("Listener has been closed")
} else {
diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs
index 064da5818..5bc04ceb5 100644
--- a/ext/net/ops_tls.rs
+++ b/ext/net/ops_tls.rs
@@ -298,10 +298,10 @@ where
.resource_table
.take::<TcpStreamResource>(rid)?;
// This TCP connection might be used somewhere else. If it's the case, we cannot proceed with the
- // process of starting a TLS connection on top of this TCP connection, so we just return a bad
- // resource error. See also: https://github.com/denoland/deno/pull/16242
+ // process of starting a TLS connection on top of this TCP connection, so we just return a Busy error.
+ // See also: https://github.com/denoland/deno/pull/16242
let resource = Rc::try_unwrap(resource_rc)
- .map_err(|_| bad_resource("TCP stream is currently in use"))?;
+ .map_err(|_| custom_error("Busy", "TCP stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tcp_stream = read_half.reunite(write_half)?;
@@ -526,7 +526,6 @@ pub async fn op_net_accept_tls(
match listener.accept().try_or_cancel(&cancel_handle).await {
Ok(tuple) => tuple,
Err(err) if err.kind() == ErrorKind::Interrupted => {
- // FIXME(bartlomieju): compatibility with current JS implementation.
return Err(bad_resource("Listener has been closed"));
}
Err(err) => return Err(err.into()),
diff --git a/ext/net/raw.rs b/ext/net/raw.rs
index f2de76065..a2ebfb5ac 100644
--- a/ext/net/raw.rs
+++ b/ext/net/raw.rs
@@ -1,8 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use crate::io::TcpStreamResource;
use crate::ops_tls::TlsStreamResource;
-use deno_core::error::bad_resource;
use deno_core::error::bad_resource_id;
+use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::AsyncRefCell;
use deno_core::CancelHandle;
@@ -70,7 +70,7 @@ impl<T: NetworkStreamListenerTrait + 'static> NetworkListenerResource<T> {
) -> Result<Option<NetworkStreamListener>, AnyError> {
if let Ok(resource_rc) = resource_table.take::<Self>(listener_rid) {
let resource = Rc::try_unwrap(resource_rc)
- .map_err(|_| bad_resource("Listener is currently in use"))?;
+ .map_err(|_| custom_error("Busy", "Listener is currently in use"))?;
return Ok(Some(resource.listener.into_inner().into()));
}
Ok(None)
@@ -334,7 +334,7 @@ pub fn take_network_stream_resource(
{
// This TCP connection might be used somewhere else.
let resource = Rc::try_unwrap(resource_rc)
- .map_err(|_| bad_resource("TCP stream is currently in use"))?;
+ .map_err(|_| custom_error("Busy", "TCP stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tcp_stream = read_half.reunite(write_half)?;
return Ok(NetworkStream::Tcp(tcp_stream));
@@ -344,7 +344,7 @@ pub fn take_network_stream_resource(
{
// This TLS connection might be used somewhere else.
let resource = Rc::try_unwrap(resource_rc)
- .map_err(|_| bad_resource("TLS stream is currently in use"))?;
+ .map_err(|_| custom_error("Busy", "TLS stream is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let tls_stream = read_half.unsplit(write_half);
return Ok(NetworkStream::Tls(tls_stream));
@@ -356,7 +356,7 @@ pub fn take_network_stream_resource(
{
// This UNIX socket might be used somewhere else.
let resource = Rc::try_unwrap(resource_rc)
- .map_err(|_| bad_resource("UNIX stream is currently in use"))?;
+ .map_err(|_| custom_error("Busy", "Unix socket is currently in use"))?;
let (read_half, write_half) = resource.into_inner();
let unix_stream = read_half.reunite(write_half)?;
return Ok(NetworkStream::Unix(unix_stream));