Module net/errors

net/errors
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. — stable modules only change additively; this one may still change.

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.

DNSFailedmsg: String

DNS resolution failed.

Ioerr: IoError

A wrapped lower-level I/O error.

Othermsg: String

An unclassified network error with a message.

Trait Implementations

impl(generic(T : Type), where(T <: ToString), T : (ToString))
impl(generic(T : Type), where(T <: ToString), T : (ToString), Format)
format : fn(self : Self, spec : str) -> String

Render self under spec. An unrecognised spec degrades to the plain to_string() rendering rather than failing.

Parameters

NameTypeNotes
selfSelf
specstr

Returns: String

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(self : NetError) -> String

Parameters

NameTypeNotes
selfNetError

Returns: String

source : (NetError) fn(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 is not expressible yet — the returned Dyn loses the Error trait on an erased receiver, so a caller can print one link but cannot follow it (#521, issues/self-trait-in-a-return-type-loses-the-trait-on-an-erased-receiver.md).

Parameters

NameTypeNotes
selfNetError

Returns: Option(dyn( + ToString))