{"record":{"id":"aa43d92023ac8473","repo":"benbjohnson/litestream","slug":"extract-timestamp-from-ltx-header-w-aa43d9","errorCode":null,"errorMessage":"extract timestamp from LTX header: %w","messagePattern":"extract timestamp from LTX header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nats/replica_client.go","lineNumber":404,"sourceCode":"\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)\n\n\t// Use TeeReader to peek at LTX header while preserving data for upload\n\tvar buf bytes.Buffer\n\tteeReader := io.TeeReader(r, &buf)\n\n\t// Extract timestamp from LTX header\n\thdr, _, err := ltx.PeekHeader(teeReader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"extract timestamp from LTX header: %w\", err)\n\t}\n\ttimestamp := time.UnixMilli(hdr.Timestamp).UTC()\n\n\t// Combine buffered data with rest of reader\n\trc := internal.NewReadCounter(io.MultiReader(&buf, r))\n\n\t// Store timestamp in NATS object headers for accurate timestamp retrieval\n\tobjectInfo, err := c.objectStore.Put(ctx, jetstream.ObjectMeta{\n\t\tName: objectPath,\n\t\tHeaders: map[string][]string{\n\t\t\tHeaderKeyTimestamp: {timestamp.Format(time.RFC3339Nano)},\n\t\t},\n\t}, rc)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to put object %s: %w\", objectPath, err)\n\t}\n\n\t// Record metrics","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/nats/replica_client.go#L386-L422","documentation":"nats.WriteLTXFile failed to peek the LTX header from the incoming stream (ltx.PeekHeader). The stream is shorter than an LTX header or has invalid magic, so the data being written to NATS is not a valid LTX file.","triggerScenarios":"Thrown at nats/replica_client.go:404 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the producer of the LTX stream for truncation/corruption","Inspect local LTX files with 'litestream ltx'; reset local state if corrupted"],"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"}