Go · Errors

Errors

import "github.com/unum-cloud/ucall" 1.0.0-rc.1 · b7577426

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ucall/go/errors.md' | claude -p "How would this fit my code?"

Every fallible call answers an error, an *ucall.Error carrying the Status the library reported and its static message, which errors.Is matches against a bare Status. A mistake the binding catches before calling the library, like a client closed before a call, reports the status the library would have used. Status prints its stable spelling, such as “connection-failed”.

client, err := ucall.NewClient(&ucall.ClientOptions{Connections: 1})
if err != nil {
	return err
}
defer client.Close()
response, err := client.Get("http://127.0.0.1:1/")
switch {
case errors.Is(err, ucall.StatusConnectionFailed):
	fmt.Println("nobody listens:", err)
case err != nil:
	return err
default:
	defer response.Close()
	fmt.Println("answered", response.StatusCode())
}

A submitted call that fails completes with Completed.Err: StatusConnectionFailed, StatusConnectionClosed, StatusTimeout, StatusHandshakeFailed or StatusPeerRejected. A request or response lookup that finds nothing fails with StatusNotFound beside an empty value, and HTTP error statuses are ordinary responses. Backend, CPUClass and Status print their stable names, like “linux-uring618” and “intel-icelake”, and BackendFromName, CPUClassFromName and StatusFromName parse them back, failing with StatusInvalidArgument on a name no value has. ucall.Version() spells the linked library’s version, candidate suffix included, and ucall.DecodePercent decodes a path or a query value, which requests hold still percent-encoded.

API

StructErrorError is one failed call: a status every caller can branch on, and the detail the status cannot carry.2
types.go:122 ↗
type Error struct {
    Status  Status
    Message string
}

Reach the status with errors.Is or errors.As.

ErrorError implements the error interface.
types.go:128 ↗
func (failure *Error) Error() string
UnwrapUnwrap exposes the status, which is what errors.Is compares.
types.go:133 ↗
func (failure *Error) Unwrap() error
EnumStatusStatus names what went wrong, in a vocabulary shared by the library and by this binding.3
types.go:57 ↗
type Status int32

Validation performed here before a call crosses reports the status the library would have reported for the same fault.

A Status is an error, so errors.Is(err, ucall.StatusConnectionFailed) matches any failure carrying it.

Values

StatusSuccessStatusSuccess means the call completed and carries no message.
StatusDeferredStatusDeferred means a submitted call is not final yet.
StatusOutOfMemoryStatusOutOfMemory means an allocation or reservation could not be satisfied.
StatusIOStatusIO means a socket or file could not be opened, read, written or closed.
StatusMalformedStatusMalformed means the peer sent bytes that do not decode as the expected protocol.
StatusInternalStatusInternal means the library violated its contract, which points at a defect.
StatusOverflowStatusOverflow means a size exceeds the representable range.
StatusUninitializedStatusUninitialized means the call needs a handle that was never made or is closed.
StatusContendedStatusContended means the call was refused rather than waited for.
StatusUnsupportedStatusUnsupported means the build, backend or machine lacks the feature.
StatusInvalidArgumentStatusInvalidArgument means an argument is missing, out of range or contradicts another.
StatusNotFoundStatusNotFound means the endpoint, header or parameter does not exist.
StatusAlreadyExistsStatusAlreadyExists means an endpoint of the same template and verb is registered, or a request was already answered.
StatusConnectionFailedStatusConnectionFailed means a lookup or a connection attempt failed.
StatusConnectionClosedStatusConnectionClosed means the connection closed before the exchange completed.
StatusTimeoutStatusTimeout means the operation exceeded its time budget.
StatusHandshakeFailedStatusHandshakeFailed means the Noise handshake failed to authenticate or agree on keys.
StatusPeerRejectedStatusPeerRejected means the peer authorizer declined the authenticated static key.
StatusWouldBlockStatusWouldBlock means a nonblocking poll or pull had no progress to report.
StatusFromNameStatusFromName reads a status back from the spelling String gives it.
types.go:112 ↗
func StatusFromName(name string) (Status, error)
ErrorError implements the error interface, so a bare Status is an errors.Is target.
types.go:109 ↗
func (status Status) Error() string
StringString renders the status as the library spells it, such as "connection-failed".
types.go:104 ↗
func (status Status) String() string