benbjohnson/litestream · error

failed to get object %s: %w

Error message

failed to get object %s: %w

What it means

Wraps objectStore.Get failure in the NATS replica client's OpenLTXFile for errors that are not 'not found'. Fires when reading the LTX object at the computed path fails due to connection/server issues; genuine missing objects are instead reported as os.ErrNotExist.

Source

Thrown at nats/replica_client.go:366

	})

	return &ltxFileIterator{files: fileInfos, index: -1}, nil
}

// OpenLTXFile returns a reader that contains an LTX file at a given TXID range.
func (c *ReplicaClient) OpenLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, offset, size int64) (io.ReadCloser, error) {
	if err := c.Init(ctx); err != nil {
		return nil, err
	}

	objectPath := c.ltxPath(level, minTXID, maxTXID)

	objectResult, err := c.objectStore.Get(ctx, objectPath)
	if err != nil {
		if isNotFoundError(err) {
			return nil, os.ErrNotExist
		}
		return nil, fmt.Errorf("failed to get object %s: %w", objectPath, err)
	}

	// Record metrics
	internal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, "GET").Inc()
	// Note: We can't get the size from NATS object reader directly, so we skip bytes counter

	// If offset is non-zero then discard the beginning bytes.
	if offset > 0 {
		if _, err := io.CopyN(io.Discard, objectResult, offset); err != nil {
			objectResult.Close()
			return nil, fmt.Errorf("failed to discard offset bytes: %w", err)
		}
	}

	// If size is non-zero then limit the reader to the size.
	if size > 0 {
		return internal.LimitReadCloser(objectResult, size), nil
	}

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check NATS connectivity and credentials
  2. Verify the object store stream is healthy (nats stream info)
  3. Retry the read operation
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at nats/replica_client.go:366 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/2e85b50287f91edd. Report an issue: GitHub.