{"record":{"id":"5a6cd6a4c21d76e9","repo":"thanos-io/thanos","slug":"read-meta-file","errorCode":null,"errorMessage":"read meta file","messagePattern":"read meta file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":426,"sourceCode":"// Repair open the block with given id in dir and creates a new one with fixed data.\n// It:\n// - removes out of order duplicates\n// - all \"complete\" outsiders (they will not accessed anyway)\n// - removes all near \"complete\" outside chunks introduced by https://github.com/prometheus/tsdb/issues/347.\n// Fixable inconsistencies are resolved in the new block.\n// TODO(bplotka): https://github.com/thanos-io/thanos/issues/378.\nfunc Repair(ctx context.Context, logger log.Logger, dir string, id ulid.ULID, source metadata.SourceType, ignoreChkFns ...ignoreFnType) (resid ulid.ULID, err error) {\n\tif len(ignoreChkFns) == 0 {\n\t\treturn resid, errors.New(\"no ignore chunk function specified\")\n\t}\n\n\tbdir := filepath.Join(dir, id.String())\n\tentropy := rand.New(rand.NewSource(time.Now().UnixNano()))\n\tresid = ulid.MustNew(ulid.Now(), entropy)\n\n\tmeta, err := metadata.ReadFromDir(bdir)\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"read meta file\")\n\t}\n\tif meta.Thanos.Downsample.Resolution > 0 {\n\t\treturn resid, errors.New(\"cannot repair downsampled block\")\n\t}\n\n\tb, err := tsdb.OpenBlock(logutil.GoKitLogToSlog(logger), bdir, nil, nil)\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open block\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, b, \"repair block reader\")\n\n\tindexr, err := b.Index()\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open index\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, indexr, \"repair index reader\")\n\n\tchunkr, err := b.Chunks()","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L408-L444","documentation":"Repair reads the block's meta.json via metadata.ReadFromDir(bdir) and wraps any failure as \"read meta file\". The block directory must contain a valid meta.json; missing, malformed, or unwritable metadata makes repair impossible. This also catches blocks whose meta.json is corrupted or whose directory is not actually a TSDB block.","triggerScenarios":"Calling Repair (or repairIndex via VerifyIndex repair paths) on a directory lacking meta.json, with invalid JSON in meta.json, or where reading the file fails due to permissions.","commonSituations":"Partially uploaded/downloaded blocks missing meta.json, manually moved block directories, objects storage sync tools that skip metadata files, permissions problems on local disks.","solutions":["Ensure the block directory contains a valid meta.json before calling Repair","Re-sync/re-download the block from object storage so meta.json is restored","Validate meta.json parses (metadata.ReadFromDir) and fix JSON syntax errors","Check filesystem permissions on the block directory"],"exampleFix":"// before\nresid, err := block.Repair(ctx, logger, dir, id, source, fn) // read meta file: no such file or directory\n// after\nif _, err := os.Stat(filepath.Join(dir, id.String(), \"meta.json\")); os.IsNotExist(err) {\n    return fmt.Errorf(\"block %s has no meta.json; re-sync it from object storage\", id)\n}\nresid, err := block.Repair(ctx, logger, dir, id, source, fn)","handlingStrategy":"validation","validationCode":"meta, err := metadata.ReadFromDir(filepath.Join(dir, id.String()))\nif err != nil {\n    return fmt.Errorf(\"block %s unusable, meta.json missing or invalid: %w\", id, err)\n}","typeGuard":"func blockDirHasMeta(dir string, id ulid.ULID) bool {\n    _, err := os.Stat(filepath.Join(dir, id.String(), \"meta.json\"))\n    return err == nil\n}","tryCatchPattern":"resid, err := block.Repair(ctx, logger, dir, id, source, fn)\nif err != nil && strings.Contains(err.Error(), \"read meta file\") {\n    return fmt.Errorf(\"re-sync block %s from object storage: %w\", id, err)\n}","preventionTips":["Only operate on block directories synced completely from object storage","Validate meta.json with metadata.ReadFromDir before any repair","Avoid manual block directory moves/copies","Check filesystem permissions on data directories"],"tags":["metadata","blocks","storage"],"backgroundTag":"file-not-found","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"}