Handle errors

Handle errors

Recognize each error the Go and TypeScript SDKs return, and know when trying again is safe.

Every SDK call returns errors you can tell apart. In Go, an error wraps a sentinel value you test with errors.Is, and some carry details you read with errors.As. In TypeScript, each error is a class you test with instanceof. Over HTTP, each is a status with a JSON body. The table says, for each error, whether to try again and whether the call may already have done its work.

Check an error

Branch on the errors you can act on, and pass the rest up:

stream := client.Address{Bucket: "demo", Key: "events"}

_, err := c.Append(ctx, stream, client.Bodies([]byte("first"))...)

switch {
case err == nil:
	fmt.Println("stored")
case errors.Is(err, client.ErrStreamNotFound):
	fmt.Println("no stream at", stream)
case errors.Is(err, client.ErrUnknownOutcome):
	fmt.Println("maybe stored: look before you send it again")
default:
	return err
}
Output, before the stream exists
no stream at demo/events

The message keeps the server's reason. errors.As reads the details of *SequenceError, *FenceError, *NotAppendedError, *ClaimRefusedError, and *PurgeError.

Errors

Error: Go, TypeScript, HTTPWhenTry againApplied
ErrStreamNotFound, StreamNotFoundError, 404The stream or bucket does not existOnce you create itNo
ErrUnauthenticated, UnauthenticatedError, 401No credential, or one the server rejectsWith a valid credentialNo
ErrFencedOut (*FenceError), FenceError, 412 with fencing_tokenThe fencing token is not the installed oneOnly to take over, with a new tokenNo
ErrSequence (*SequenceError), SequenceError, 412 with tailA match sequence number was not the stream's next oneAfter you read from the tailNo, unless Resent / resent is true
ErrBatchTooLarge, BatchTooLargeError, 400 with reason: batch_too_largeOne append holds more than one batchAs several appendsNo
ErrRecordTooLarge, RecordTooLargeError, 400A record is over 1 MiB or 64 headers, or the server refused another argument, such as a timestamp or a bucket's locationAfter you fix itNo
ErrTrimmed, TrimmedError, 410A read starts below the trim pointWith the clamp optionNo
ErrPositionPerRange, PositionPerRangeError, 400 with reason: position_per_rangeA scalable stream got a sequence number or tail offsetFrom a bookmark, the beginning, the tail, or a timeNo
ErrMatchOnScalable, RecordTooLargeError, 400A scalable stream got a match sequence numberWithout the matchNo
ErrUnavailable, UnavailableError, 503 or 429No node took the call within the retry budgetLaterNo
ErrUnknownOutcome, UnknownOutcomeError, a timeout or dropped connectionAn append was sent and no answer came backOnly with a match sequence number, or after you lookMaybe
ErrNotAppended (*NotAppendedError), NotAppendedErrorA producer ended on an earlier batch's refusal before it read this oneOn a new producerNo
ErrHolderUnresolvable, HolderUnresolvableErrorThe stream leader's advertised address does not resolve where you runNo: the operator fixes the addressNo
ErrWireOnly, WireOnlyErrorAn admin call on a client that uses HTTPOver gRPCNo
ErrPrefixUnsupported, PrefixUnsupportedErrorThe server is too old to list by prefixAfter the server is upgradedNo
ErrLocation, LocationMismatchErrorA bucket names a location other than the client'sFrom a client in that locationNo
ErrMalformedAPIKey, MalformedApiKeyErrorThe api key is not well formed; refused when you create the clientWith the right keyNo
ErrQueueAddress, QueueAddressError, 409 with reason: queue_addressA stream call reached the address of a queueWith the queue's own callsNo
A client: closed error, ClosedErrorA call on a client or producer you closedOn a new oneNo
None, SessionUnsupportedErrorA browser asked for a producerAs a one-shot appendNo

In Go, an unknown outcome caused by an outage also matches ErrUnavailable, so test for ErrUnknownOutcome first. In TypeScript, UnknownOutcomeError keeps the UnavailableError as its cause.

When no error type fits

Some refusals have no sentinel or class of their own. They reach Go as the gRPC status, and TypeScript as a TransportError with the code's name:

_, err := c.CreateStream(ctx, client.StreamOptions{Bucket: "demo", Key: "events"})

// No sentinel covers a taken address: read the gRPC code.
if status.Code(err) == codes.AlreadyExists {
	fmt.Println("the stream exists already")
	return nil
}

if err != nil {
	return err
}

fmt.Println("created")
Output, run twice
created
the stream exists already
Code, HTTPWhen
AlreadyExists, 409A bucket name or stream address is taken
PermissionDenied, 403The credential lacks the grant the call needs
FailedPrecondition, 503A refusal that lasts: a bucket that still holds streams, or a class the node cannot serve

Over HTTP, that last refusal comes with Retry-After: 1 although it does not pass. Look at the message before you retry it.

What the SDK retries

The SDK retries a call that failed for a passing reason: a node that is restarting, draining, or busy, or a stream that is moving to another node or recovering. It waits 10 ms, doubles the wait up to 1 second, and waits at least 500 ms after a node said it is busy, or as long as the node asked. It stops at the retry budget, 30 seconds by default, and returns ErrUnavailable / UnavailableError with the last failure inside. Every other failure returns at once. So does a failing credential, such as a token function that returns an error, before anything is sent.

Reads, subscriptions, tail checks, trims, fences, and queue calls retry this way. A one-shot append retries only while it cannot have been stored. Calls that create, get, change, list, or delete streams and buckets are sent once, so retry those yourself; a creation token makes a create safe to repeat.

Reconnects

When a producer's session breaks, the producer reconnects, to the stream's new leader if it moved, and sends every batch that has no acknowledgement again, in order. A plain batch whose acknowledgement was lost is then stored twice; a batch with a match sequence number is not. The reconnect counts as done once a node answers a batch. Until then, every session it opens spends the same retry budget, with waits of up to 1 second between them.

A producer stops for good in two cases. When the budget runs out, its appends fail with ErrUnavailable, and the ones it had sent with ErrUnknownOutcome. When Nova refuses a batch, that batch fails with the refusal, and the batches after it with ErrNotAppended, which you can send again. Either way, open a new producer to go on.

A subscription resumes after the last record it delivered, so you see no record twice. Each delivery gives it a full retry budget again, and a reopen for an expired token spends none.

Queue errors

Queue calls add these:

Error: Go, TypeScript, HTTPWhenWhat to do
ErrInvalidQueueConfig, InvalidQueueConfigError, 400A queue's settings were refused: no kind, a kind or claims mode other than the queue's, or a setting out of boundsFix the settings. Nothing changed
ErrMessage, MessageError, 400A queue call or worker was refused for its arguments, such as a reserved nova- header or a bad idempotency keyFix the call. Nothing was done
ErrQueueExists, QueueExistsError, 409A queue or stream already holds the addressUse the queue there, or another address
ErrDelayOnKeyOrdered, DelayOnKeyOrderedError, 400 with reason: delay_on_key_orderedA delayed message was sent to a key-ordered queueSend it without a delay
ErrClaimRefused (*ClaimRefusedError), ClaimRefusedError, 409 or 400 with reason: claim_refusedThe queue would not ack, nack, or extend a claim; the refusal says whyAct on the refusal
*PurgeError, PurgeErrorA purge stopped part way; it says how many messages it removedPurge again later
ErrBatchTooLarge, BatchTooLargeError, 400A send holds more than one batch, counting the headers the queue addsSplit it into several sends; see send size

See also

On this page