Rust · Errors

Errors

use ucall::Error;use ucall::Status;use ucall::*; 1.0.0-rc.1 · 60202332

Every fallible call answers ucall::Result, whose Error carries the Status the library reported and a static message beside it, so nothing allocates on the failure path. A mistake the binding catches before calling the library, like polling an event loop the server lacks, reports the status the library would have used. Status prints its stable spelling, such as “connection-failed”, and a status a newer library added reads as Status::Internal.

use ucall::*;

let mut client = Client::new(ClientOptions { connections: 1, ..Default::default() })?;
match client.get("http://127.0.0.1:1/") {
    Ok(response) => println!("answered {}", response.status_code().0),
    Err(error) if error.status == Status::ConnectionFailed => println!("nobody listens: {error}"),
    Err(error) => return Err(error.into()),
}

A submitted call that fails completes with Err in Completed::response: Status::ConnectionFailed, Status::ConnectionClosed, Status::Timeout, Status::HandshakeFailed or Status::PeerRejected. A request lookup that finds nothing answers None, and HTTP error statuses are ordinary responses. Backend and CPUClass print and parse their stable names, like “linux-uring618” and “intel-icelake”, failing with Status::InvalidArgument on a name no value has, and Status::from_name reads a status back from its spelling. ucall::version() spells the linked library’s version, candidate suffix included. ucall::decode_percent decodes a path or a query value, which requests lend still percent-encoded.

API

Types

ResultThe result of every fallible call in this crate.
lib.rs:268 ↗
pub type Result<Value> = Result<Value, Error>;
StructErrorA failure, whether the library reported it or the binding caught it before the call.
types.rs:252 ↗
pub struct Error

Messages are static storage, so nothing allocates on the failure path.

use ucall::{Client, ClientOptions, Status};

let refused = Client::new(ClientOptions::default()).err().expect("a client needs connections");
assert_eq!(refused.status, Status::InvalidArgument);
println!("{refused}"); // "invalid-argument: ..."

Fields

statusStatusWhat went wrong, to branch on.
message&'static strThe detail the status alone cannot carry.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Display, Error
EnumStatusWhy a call failed, numbered as the library numbers it; success is the Ok of a Result.1
types.rs:153 ↗
pub enum Status

Values

Deferred1A reply is still sending a file or path part, as Deferred::status reports it.
OutOfMemory2An allocation or reservation could not be satisfied.
IO7A socket or file could not be opened, read, written, or closed.
Malformed9The peer supplied bytes that cannot be decoded as the expected protocol.
Internal10The library violated its contract, which points at a defect.
Overflow11The requested size exceeds the representable range.
Uninitialized12The call needs a handle that was never initialized.
Contended14The call was refused rather than waited for, like a submission to a full client.
Unsupported16The build, backend, or machine does not implement the requested feature.
InvalidArgument17An argument is missing, out of range, or contradicts another argument.
NotFound18The requested endpoint, header, or parameter does not exist.
AlreadyExists19An endpoint with the same template and verb is already registered.
ConnectionFailed20DNS lookup or connection establishment failed.
ConnectionClosed21The connection closed before the exchange completed.
Timeout22The operation exceeded its time budget.
HandshakeFailed23The Noise handshake failed to authenticate or agree on keys.
PeerRejected24The peer authorizer declined the authenticated static key.
WouldBlock25Nothing was ready: a nonblocking poll had no progress to report, a pull on the polling thread found no body bytes yet, or a stream's peer lags behind its appended parts.

Implements

Clone, Copy, StructuralPartialEq, PartialEq, Eq, Debug, Hash, Display
from_nameReads a status back from its stable spelling, like "out-of-memory", or None for a name no failure has, "success" among them.
types.rs:224 ↗
pub fn from_name(name: &str) -> Option<Self>