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
}no stream at demo/eventsThe message keeps the server's reason. errors.As reads the details of *SequenceError, *FenceError, *NotAppendedError, *ClaimRefusedError, and *PurgeError.
Errors
| Error: Go, TypeScript, HTTP | When | Try again | Applied |
|---|---|---|---|
ErrStreamNotFound, StreamNotFoundError, 404 | The stream or bucket does not exist | Once you create it | No |
ErrUnauthenticated, UnauthenticatedError, 401 | No credential, or one the server rejects | With a valid credential | No |
ErrFencedOut (*FenceError), FenceError, 412 with fencing_token | The fencing token is not the installed one | Only to take over, with a new token | No |
ErrSequence (*SequenceError), SequenceError, 412 with tail | A match sequence number was not the stream's next one | After you read from the tail | No, unless Resent / resent is true |
ErrBatchTooLarge, BatchTooLargeError, 400 with reason: batch_too_large | One append holds more than one batch | As several appends | No |
ErrRecordTooLarge, RecordTooLargeError, 400 | A record is over 1 MiB or 64 headers, or the server refused another argument, such as a timestamp or a bucket's location | After you fix it | No |
ErrTrimmed, TrimmedError, 410 | A read starts below the trim point | With the clamp option | No |
ErrPositionPerRange, PositionPerRangeError, 400 with reason: position_per_range | A scalable stream got a sequence number or tail offset | From a bookmark, the beginning, the tail, or a time | No |
ErrMatchOnScalable, RecordTooLargeError, 400 | A scalable stream got a match sequence number | Without the match | No |
ErrUnavailable, UnavailableError, 503 or 429 | No node took the call within the retry budget | Later | No |
ErrUnknownOutcome, UnknownOutcomeError, a timeout or dropped connection | An append was sent and no answer came back | Only with a match sequence number, or after you look | Maybe |
ErrNotAppended (*NotAppendedError), NotAppendedError | A producer ended on an earlier batch's refusal before it read this one | On a new producer | No |
ErrHolderUnresolvable, HolderUnresolvableError | The stream leader's advertised address does not resolve where you run | No: the operator fixes the address | No |
ErrWireOnly, WireOnlyError | An admin call on a client that uses HTTP | Over gRPC | No |
ErrPrefixUnsupported, PrefixUnsupportedError | The server is too old to list by prefix | After the server is upgraded | No |
ErrLocation, LocationMismatchError | A bucket names a location other than the client's | From a client in that location | No |
ErrMalformedAPIKey, MalformedApiKeyError | The api key is not well formed; refused when you create the client | With the right key | No |
ErrQueueAddress, QueueAddressError, 409 with reason: queue_address | A stream call reached the address of a queue | With the queue's own calls | No |
A client: closed error, ClosedError | A call on a client or producer you closed | On a new one | No |
None, SessionUnsupportedError | A browser asked for a producer | As a one-shot append | No |
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")created
the stream exists already| Code, HTTP | When |
|---|---|
AlreadyExists, 409 | A bucket name or stream address is taken |
PermissionDenied, 403 | The credential lacks the grant the call needs |
FailedPrecondition, 503 | A 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, HTTP | When | What to do |
|---|---|---|
ErrInvalidQueueConfig, InvalidQueueConfigError, 400 | A queue's settings were refused: no kind, a kind or claims mode other than the queue's, or a setting out of bounds | Fix the settings. Nothing changed |
ErrMessage, MessageError, 400 | A queue call or worker was refused for its arguments, such as a reserved nova- header or a bad idempotency key | Fix the call. Nothing was done |
ErrQueueExists, QueueExistsError, 409 | A queue or stream already holds the address | Use the queue there, or another address |
ErrDelayOnKeyOrdered, DelayOnKeyOrderedError, 400 with reason: delay_on_key_ordered | A delayed message was sent to a key-ordered queue | Send it without a delay |
ErrClaimRefused (*ClaimRefusedError), ClaimRefusedError, 409 or 400 with reason: claim_refused | The queue would not ack, nack, or extend a claim; the refusal says why | Act on the refusal |
*PurgeError, PurgeError | A purge stopped part way; it says how many messages it removed | Purge again later |
ErrBatchTooLarge, BatchTooLargeError, 400 | A send holds more than one batch, counting the headers the queue adds | Split it into several sends; see send size |