{"record":{"id":"67da7af5749688db","repo":"thanos-io/thanos","slug":"rewrite-block","errorCode":null,"errorMessage":"rewrite block","messagePattern":"rewrite block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":472,"sourceCode":"\t\treturn resid, errors.Wrap(err, \"open chunk writer\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, chunkw, \"repair chunk writer\")\n\n\tindexw, err := index.NewWriter(context.TODO(), filepath.Join(resdir, IndexFilename))\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open index writer\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, indexw, \"repair index writer\")\n\n\t// TODO(fabxc): adapt so we properly handle the version once we update to an upstream\n\t// that has multiple.\n\tresmeta := *meta\n\tresmeta.ULID = resid\n\tresmeta.Stats = tsdb.BlockStats{} // Reset stats.\n\tresmeta.Thanos.Source = source    // Update source.\n\n\tif err := rewrite(ctx, logger, indexr, chunkr, indexw, chunkw, &resmeta, ignoreChkFns); err != nil {\n\t\treturn resid, errors.Wrap(err, \"rewrite block\")\n\t}\n\tresmeta.Thanos.SegmentFiles = GetSegmentFiles(resdir)\n\tif err := resmeta.WriteToDir(logger, resdir); err != nil {\n\t\treturn resid, err\n\t}\n\t// TSDB may rewrite metadata in bdir.\n\t// TODO: This is not needed in newer TSDB code. See https://github.com/prometheus/tsdb/pull/637.\n\tif err := meta.WriteToDir(logger, bdir); err != nil {\n\t\treturn resid, err\n\t}\n\treturn resid, nil\n}\n\nvar castagnoli = crc32.MakeTable(crc32.Castagnoli)\n\nfunc IgnoreCompleteOutsideChunk(mint, maxt int64, _, curr *chunks.Meta) (bool, error) {\n\tif curr.MinTime > maxt || curr.MaxTime < mint {\n\t\t// \"Complete\" outsider. Ignore.","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L454-L490","documentation":"The rewrite step inside block Repair failed while copying series/chunks into the new block (via rewrite with the ignore function). Indicates corrupt source index/chunks or an error from the chunk iterator; the partially written result is discarded.","triggerScenarios":"Thrown at pkg/block/index.go:472 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the underlying rewrite error for the failing series","Verify source block integrity","Re-download the block and retry repair"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}