Module net/errors

net/errors
Stability: unstable — may still change; see below.

The network error type — NetError, the payload every throw in std/net carries.

It is the network-facing subset of IoError promoted to its own variants (ConnectionRefused, AddrInUse, TimedOut, …) so a caller can match the cases it can actually recover from, plus Io(err) for everything the kernel reports that is not network-specific. from_io does that promotion; check(result, exn) is the shape every std/net call site uses — a negative syscall return is turned into a NetError and THROWN (D1), which is why the byte counts those calls resolve to are always real counts.

Stability

unstable — Other(msg : String) is the open question. It is where every ADDRESS-PARSE failure currently lands (IpAddr.parse, SocketAddr.parse, the port scanner), so a caller that wants to tell "port above 65535" from "host is not an IP" has to read English text, which D1 rules out. Rust puts that case in a separate AddrParseError rather than in its I/O error, and std/net/addr's own ## Stability names the same decision. Since callers match this enum, adding the variants that would replace Other is not an additive change; freezing waits on that split.

Types

NetError enum
NetError

Network-specific error type wrapping lower-level I/O errors.

Variants

VariantFieldsDescription
ConnectionRefused

The remote host refused the connection.

ConnectionReset

The connection was reset by the remote host.

ConnectionAborted

The connection was aborted locally.

AddrInUse

The address is already in use.

AddrNotAvailable

The requested address is not available.

TimedOut

The operation timed out.

HostUnreachable

The remote host is unreachable.

NetworkUnreachable

The network is unreachable.

DNSFailedhost: String, reason: DnsError

DNS resolution of host failed, for reason.

Ioerr: IoError

A wrapped lower-level I/O error.

Othermsg: String

An unclassified network error with a message.

Trait Implementations

impl(NetError, ...)
from_io : (NetError) fn(err : IoError) -> NetError

Convert an IoError into the corresponding NetError variant.

Parameters

NameTypeNotes
errIoError

Returns: NetError

impl(NetError, ...)
check : (NetError) fn(result : i32, exn : Exception) -> i32

Check a raw syscall result and throw on error. Positive values are returned as-is; negative values are converted to a NetError and thrown.

Parameters

NameTypeNotes
resulti32
exnException

Returns: i32

Methods
to_string : (NetError) fn(inout(self) : NetError) -> String

Parameters

NameTypeNotes
selfNetError

Returns: String

source : (NetError) fn(inout(self) : NetError) -> Option(dyn(ToString + ))

The error that caused this one, or .None at the root of the chain.

Rust's Error::source. Defaulted to .None, so an error with nothing underneath it implements the trait by saying only what it is; a wrapper overrides it to hand back what it wrapped. Walking the chain to the root cause works as of 2026-09-14 — the returned Dyn used to lose the Error trait on an erased receiver, so a caller could print one link but not follow it (#521, issues/fixed/self-trait-in-a-return-type-loses-the-trait-on-an-erased-receiver.md).

Parameters

NameTypeNotes
selfNetError

Returns: Option(dyn(ToString + ))

DnsError enum
DnsError

Why a name lookup failed. The runtime classifies the resolver's EAI_* answer the same way on every platform (std/sys/dns's DNS_ERR_*), so a caller can retry TryAgain and give up on NotFound.

Variants

VariantFieldsDescription
NotFound

The name does not exist (EAI_NONAME, EAI_NODATA). Permanent.

TryAgain

A temporary resolver failure (EAI_AGAIN). Retrying may succeed.

Fail

A permanent resolver failure (EAI_FAIL).

NoMemory

The resolver ran out of memory (EAI_MEMORY).

Other

An unclassified network error with a message.

Trait Implementations

Methods
clone : (DnsError) fn(inout(self) : DnsError) -> DnsError

Parameters

NameTypeNotes
selfDnsError

Returns: DnsError

to_string : (DnsError) fn(inout(self) : DnsError) -> String

Parameters

NameTypeNotes
selfDnsError

Returns: String

source : (DnsError) fn(inout(self) : DnsError) -> Option(dyn(ToString + ))

The error that caused this one, or .None at the root of the chain.

Rust's Error::source. Defaulted to .None, so an error with nothing underneath it implements the trait by saying only what it is; a wrapper overrides it to hand back what it wrapped. Walking the chain to the root cause works as of 2026-09-14 — the returned Dyn used to lose the Error trait on an erased receiver, so a caller could print one link but not follow it (#521, issues/fixed/self-trait-in-a-return-type-loses-the-trait-on-an-erased-receiver.md).

Parameters

NameTypeNotes
selfDnsError

Returns: Option(dyn(ToString + ))