Module net/errors
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
Network-specific error type wrapping lower-level I/O errors.
Variants
| Variant | Fields | Description |
|---|---|---|
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. | |
DNSFailed | msg: String | DNS resolution failed. |
Io | err: IoError | A wrapped lower-level I/O error. |
Other | msg: 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) -> StringRender self under spec. An unrecognised spec degrades to the plain
to_string() rendering rather than failing.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Self | |
spec | str |
Returns: String
impl(NetError, ...)
impl(NetError, ...)
check : (NetError) fn(result : i32, exn : Exception) -> i32Check a raw syscall result and throw on error.
Positive values are returned as-is; negative values are converted to a NetError and thrown.
Parameters
| Name | Type | Notes |
|---|---|---|
result | i32 | |
exn | Exception |
Returns: i32
Methods
to_string : (NetError) fn(self : NetError) -> Stringsource : (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
| Name | Type | Notes |
|---|---|---|
self | NetError |