{"record":{"id":"66aba1e5ca1a8cba","repo":"benbjohnson/litestream","slug":"failed-to-discard-offset-bytes-w","errorCode":null,"errorMessage":"failed to discard offset bytes: %w","messagePattern":"failed to discard offset bytes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nats/replica_client.go","lineNumber":377,"sourceCode":"\tobjectPath := c.ltxPath(level, minTXID, maxTXID)\n\n\tobjectResult, err := c.objectStore.Get(ctx, objectPath)\n\tif err != nil {\n\t\tif isNotFoundError(err) {\n\t\t\treturn nil, os.ErrNotExist\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to get object %s: %w\", objectPath, err)\n\t}\n\n\t// Record metrics\n\tinternal.OperationTotalCounterVec.WithLabelValues(ReplicaClientType, \"GET\").Inc()\n\t// Note: We can't get the size from NATS object reader directly, so we skip bytes counter\n\n\t// If offset is non-zero then discard the beginning bytes.\n\tif offset > 0 {\n\t\tif _, err := io.CopyN(io.Discard, objectResult, offset); err != nil {\n\t\t\tobjectResult.Close()\n\t\t\treturn nil, fmt.Errorf(\"failed to discard offset bytes: %w\", err)\n\t\t}\n\t}\n\n\t// If size is non-zero then limit the reader to the size.\n\tif size > 0 {\n\t\treturn internal.LimitReadCloser(objectResult, size), nil\n\t}\n\n\treturn objectResult, nil\n}\n\n// WriteLTXFile writes an LTX file to the replica.\nfunc (c *ReplicaClient) WriteLTXFile(ctx context.Context, level int, minTXID, maxTXID ltx.TXID, r io.Reader) (*ltx.FileInfo, error) {\n\tif err := c.Init(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\tobjectPath := c.ltxPath(level, minTXID, maxTXID)","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/nats/replica_client.go#L359-L395","documentation":"Wraps io.CopyN failure while discarding the leading 'offset' bytes of a fetched NATS object in OpenLTXFile. Fires when a non-zero read offset was requested (partial LTX read) but the underlying stream ends or errors before the offset is reached.","triggerScenarios":"Thrown at nats/replica_client.go:377 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the requested offset/size match the real object size (corruption or truncated object)","Re-upload the affected LTX file if the object store copy is truncated","Inspect the wrapped error for read failures"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}