Errors
Sentinel errors, the server’s error codes, and redirects.
ErrRemote
var ErrRemote = ErrRemote
ErrRemote matches any error frame the server returned where a response was expected: errors.Is(err, ErrRemote).
ErrRetriesExhausted
var ErrRetriesExhausted = ErrRetriesExhausted
ErrRetriesExhausted matches an ingest or a read the server shed on every attempt. The last RemoteError is wrapped, so errors.As still reaches its code and hint.
ErrAmbiguous
var ErrAmbiguous = ErrAmbiguous
ErrAmbiguous matches a write whose outcome cannot be determined: the request was in flight when the connection failed. Reconcile by querying the range back — do NOT blindly re-send.
ErrClientClosed
var ErrClientClosed = ErrClientClosed
ErrClientClosed matches every operation on a Client whose connection is gone — closed by the caller, or torn down by a transport error.
ErrRequestTimeout
var ErrRequestTimeout = ErrRequestTimeout
ErrRequestTimeout matches a request the server did not answer within Options.RequestTimeout. The request may still execute server-side; its late response is discarded, never misdelivered to a later request.
ErrCircuitOpen
var ErrCircuitOpen = ErrCircuitOpen
ErrCircuitOpen matches an operation refused without being attempted, because the endpoint has failed to connect too many times in a row.
ErrInvalidOptions
var ErrInvalidOptions = ErrInvalidOptions
ErrInvalidOptions matches a Dial rejected at construction: an option value that cannot be intended (negative timeout, over-limit token validity, a frame cap below the 4KiB floor). Zero values are valid and mean “default”.
ErrRedirect
var ErrRedirect = ErrRedirect
ErrRedirect matches a request refused because the node asked does not serve the stream’s partition. It is RE-TARGETABLE, not retryable: re-sending to the same address gets the same answer.
The node emits a redirect BEFORE the request reaches storage, so it holds nothing — unlike ErrAmbiguous, a redirected write provably did not land, and sending it to the node named is a first attempt rather than a retry.
Use RedirectError to read where to go. This client does not follow redirects on its own: it holds one connection to one address, and a per-node connection pool is future work.
ErrSlowConsumer
var ErrSlowConsumer = ErrSlowConsumer
ErrSlowConsumer matches the server evicting a subscription whose consumer fell behind. The eviction ends the SUBSCRIPTION, not the connection: the Client stays usable and re-subscribing on it works. Recovery is a re-subscribe with backfill, not a resumption — batches were dropped.
ErrForeignBatch
var ErrForeignBatch = ErrForeignBatch
ErrForeignBatch matches a delivery for a stream this Subscription did not subscribe to, which means two subscriptions are sharing one Client.
ErrBatcherClosed
var ErrBatcherClosed = ErrBatcherClosed
ErrBatcherClosed matches an Add on a closed Batcher.
ErrNoColumns
var ErrNoColumns = ErrNoColumns
ErrNoColumns is returned by QueryColumns for a request that names no column.
RemoteError
RemoteError is the decoded server error; reach it with errors.As to branch on Code or ask RetryAfter whether a retry is appropriate.
type RemoteError struct {
Code ErrorCode
Message string
// RetryAfterMillis is the server's backoff hint, 0 if it gave none.
RetryAfterMillis uint16
}
RemoteError is a decoded ERROR frame. It preserves the fields a client has to branch on — the code, and the backoff hint that comes with ErrorCodeOverloaded.
Formatting them into a string, which is what this path used to do, made the backpressure signal unusable: a caller could see that ingest failed but not whether retrying was appropriate, which is the entire distinction between ErrorCodeOverloaded (nothing stored, retry the batch after backing off) and ErrorCodeInternal (do not replay blindly). Use errors.As to reach it; errors.Is(err, ErrRemote) still matches, so existing callers are unaffected.
func (e *RemoteError) Error() string
func (e *RemoteError) Is(target error) bool
Is reports ErrRemote so callers written against the sentinel keep working, and ErrSlowConsumer for the one code a subscriber has to branch on by meaning rather than by number. Both stay reachable through errors.As on the concrete type; this only spares the common case an As plus a Code compare.
func (e *RemoteError) RetryAfter() (time.Duration, bool)
RetryAfter reports the backoff the server asked for and whether this error is one a client should retry at all. Only ErrorCodeOverloaded is retryable today: it is the one code that promises nothing was stored.
ErrorCode
ErrorCode identifies why the server refused an operation.
type ErrorCode uint16
ErrorCode identifies the class of failure carried in an ERROR frame.
const (
// ErrorCodeProtocol indicates a malformed or unexpected frame.
ErrorCodeProtocol ErrorCode = 0x0001
// ErrorCodePayloadTooLarge indicates a frame exceeded the payload limit.
ErrorCodePayloadTooLarge ErrorCode = 0x0002
// ErrorCodeUnauthorized indicates a permission or authentication failure.
ErrorCodeUnauthorized ErrorCode = 0x0003
// ErrorCodeInternal indicates a server-side error.
ErrorCodeInternal ErrorCode = 0x0004
// ErrorCodeUnsupported indicates a well-formed frame whose type this
// server does not implement (e.g. subscriptions before Phase 3.3).
ErrorCodeUnsupported ErrorCode = 0x0005
// ErrorCodeSlowConsumer indicates a subscription was evicted because the
// client did not drain its delivery queue: the server dropped
// network.subscription.drop_limit batches in a row for it. The
// subscription is gone; the connection stays open and its other
// subscriptions and queries are unaffected
// (TestServer_SlowSubscriberIsEvictedWithSlowConsumerError).
ErrorCodeSlowConsumer ErrorCode = 0x0006
// ErrorCodeOverloaded indicates the server could not absorb a write: an
// ingest buffer stayed at its watermark for longer than the configured wait,
// so the batch was shed rather than queued. NOTHING from the batch was
// stored — it is safe and expected to retry the whole thing after backing
// off, ideally by RetryAfterMillis (TestServer_ShedIngestAnswersOverloaded).
//
// It is the load-shedding tier of backpressure, not the first line of it.
// Ordinary overload is absorbed by the server simply not reading the socket
// while it waits for room, which closes the client's TCP window; this code
// appears only when that wait ran out. A client seeing it should slow down,
// not merely retry in a tight loop.
//
// Distinct from ErrorCodeInternal on purpose: internal means a bug or a
// failed device and the request should not be replayed blindly, whereas
// this means "try again shortly". Collapsing them is what makes a load
// spike look like data corruption in the dashboards.
//
// Two refusals that are not load reuse it, because they share its promise
// — raised before anything is dispatched, and cleared by waiting: a
// partition draining for a cutover (§7.4.3), and a new primary still
// replaying the replica log its copy kept (§7.4.10,
// TestUnavailable_APrimaryStillReplayingItsLogRefusesRetryably). Every
// client already retries it, so neither needed new client semantics.
ErrorCodeOverloaded ErrorCode = 0x0007
// ErrorCodeStalePlacement indicates THIS NODE could not place the request:
// it has no directory entry for the partition, or its entry is older than
// the epoch the write carried. Either way the node is the one that is
// behind, not the client.
//
// It is distinct from a REDIRECT, which is what a node sends when it knows
// where the partition belongs. This code means the opposite -- the node
// cannot say -- so there is nowhere to point the client and the only honest
// answer is "retry". It carries a backoff hint for that reason.
//
// It is distinct from ErrorCodeOverloaded too, though both mean "try
// again": overloaded is about capacity and resolves by slowing down, this
// is about consensus catch-up and resolves by waiting. Collapsing them
// would make a lagging replica look like a load problem.
ErrorCodeStalePlacement ErrorCode = 0x0008
// ErrorCodePartitionUnavailable indicates nobody can serve the request's
// partition right now, for one of two reasons. Its primary is on a node
// the cluster has FENCED (§7.4.6): the answering node knows where the
// partition lives and that the address is dead, so it neither serves nor
// redirects — sending a client to an address the cluster has stopped
// believing is a black hole, and a connection error from there is about
// the network, not about the partition. Or the primary is the answering
// node and it holds no current lease (§7.4.10): it cannot rule out having
// been replaced. Refused before anything is dispatched, like a redirect,
// so a caller re-sending later is making a first attempt.
//
// It carries NO retry hint. Nothing about it heals on a client's timer:
// the partition comes back when its node is acknowledged again, or when
// the cluster fails it over to an in-sync copy — a liveness timeout after
// the fence, if a copy exists, on a clock the client cannot see — and a
// client that waited a hinted interval would only learn the same thing
// again (TestUnavailable_APartitionWithADownPrimaryIsRefusedNotRedirected).
ErrorCodePartitionUnavailable ErrorCode = 0x0009
// ErrorCodeDerivedStream indicates a client write to a DERIVED stream
// (Phase 8 §8.1) that did not carry FlagOverwrite. The node writes that
// stream itself from its source, so a client writing it unawares would
// interleave its bars with the deriver's. Refused before anything is
// stored and carrying no retry hint: re-sending changes nothing, and
// re-sending WITH the flag is a decision the caller makes on purpose
// (TestServer_AWriteToADerivedStreamIsRefusedWithoutOverwrite).
ErrorCodeDerivedStream ErrorCode = 0x000A
)
ERROR frame codes.
v1 divergence: these numbers are NOT the ones in docs/overview/api-and-networking.md’s error table, which allocates 0x0001 to INVALID_FRAME and 0x0005 to PARTITION_NOT_OWNED. That table describes a partitioned cluster; this build serves a single node and numbers only the classes it can actually produce. Treat the constants below as the implemented vocabulary and the spec table as intent.
func (c ErrorCode) String() string
String returns the lowercase name of the error code, used as the error_type label on mirexa_errors_total (Server.writeError) and in logs. The vocabulary is closed: every value is a compile-time literal, never derived from peer input, so the label cardinality is bounded at eleven (the ten named codes plus “unknown”). TestErrorCodeOverloaded_HasAMetricLabel asserts every named code has a distinct case, because a code without one silently merges into the “unknown” bucket — and the list it checks is written by hand, so a new code must be added to it: stale_placement went unlisted from §7.4.9 until §7.4.6 added the next one.
Error codes
const (
ErrorCodeProtocol = ErrorCodeProtocol
ErrorCodeUnauthorized = ErrorCodeUnauthorized
ErrorCodeUnsupported = ErrorCodeUnsupported
ErrorCodeInternal = ErrorCodeInternal
ErrorCodePayloadTooLarge = ErrorCodePayloadTooLarge
ErrorCodeSlowConsumer = ErrorCodeSlowConsumer
ErrorCodeOverloaded = ErrorCodeOverloaded
// ErrorCodeDerivedStream refuses a write to a stream the node derives
// from its source; Client.OverwriteCandles (or FillGapRequest.Overwrite)
// writes it on purpose.
ErrorCodeDerivedStream = ErrorCodeDerivedStream
)
Error codes a caller can branch on. Overloaded is the only code that promises nothing was stored, and therefore the only retryable one.
RedirectError
RedirectError names the node that serves a stream’s partition, and the partition EPOCH the answer was true at.
It is a typed error rather than a message to parse precisely so a caller never has to classify one by its text — errors.As it and read Addr.
type RedirectError struct {
wire.Redirect
}
RedirectError reports that the node asked does not serve a stream’s partition, and names the node that does.
func (e *RedirectError) Error() string
func (e *RedirectError) Is(target error) bool
Is reports true for ErrRedirect, so errors.Is(err, ErrRedirect) works for a caller that does not want the concrete type.