{"record":{"id":"fb5e346867c10002","repo":"thanos-io/thanos","slug":"unexpected-meta-file-version-d","errorCode":null,"errorMessage":"unexpected meta file version %d","messagePattern":"unexpected meta file version (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/metadata/meta.go","lineNumber":281,"sourceCode":"func ReadFromDir(dir string) (*Meta, error) {\n\tf, err := os.Open(filepath.Join(dir, filepath.Clean(MetaFilename)))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn Read(f)\n}\n\n// Read the block meta from the given reader.\nfunc Read(rc io.ReadCloser) (_ *Meta, err error) {\n\tdefer runutil.ExhaustCloseWithErrCapture(&err, rc, \"close meta JSON\")\n\n\tvar m Meta\n\tif err = json.NewDecoder(rc).Decode(&m); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif m.Version != TSDBVersion1 {\n\t\treturn nil, errors.Errorf(\"unexpected meta file version %d\", m.Version)\n\t}\n\n\tversion := m.Thanos.Version\n\tif version == 0 {\n\t\t// For compatibility.\n\t\tversion = ThanosVersion1\n\t}\n\n\tif version != ThanosVersion1 {\n\t\treturn nil, errors.Errorf(\"unexpected meta file Thanos section version %d\", m.Version)\n\t}\n\n\tif m.Thanos.Labels == nil {\n\t\t// To avoid extra nil checks, allocate map here if empty.\n\t\tm.Thanos.Labels = make(map[string]string)\n\t}\n\treturn &m, nil\n}","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/metadata/meta.go#L263-L299","documentation":"Read rejects meta.json files whose TSDB version field is not TSDBVersion1 (1). This is a guard: the Thanos meta reader only understands Prometheus TSDB meta version 1 files, so any other version is treated as unreadable rather than misinterpreted.","triggerScenarios":"Calling Read (or ReadFromDir) on a meta.json where the top-level \"version\" field is not 1 — e.g. a future Prometheus format or a manually crafted/edited file with a different version.","commonSituations":"Reading blocks written by a newer Prometheus/Thanos that bumped the meta version; hand-edited meta.json; blocks produced by incompatible tooling; file corruption changing the version field.","solutions":["Check meta.json's \"version\" field; it must be 1 for this reader.","Regenerate the block with a compatible Prometheus/Thanos version (TSDB meta v1).","Upgrade Thanos if the block was written by newer tooling that emits a newer meta version.","Remove corrupted or hand-modified blocks and re-upload/re-sync from source."],"exampleFix":"// before (meta.json)\n{\"version\": 2, ...}\n// after\n{\"version\": 1, ...}","handlingStrategy":"validation","validationCode":"var raw struct{ Version int `json:\"version\"` }\nb, _ := os.ReadFile(filepath.Join(bdir, \"meta.json\"))\nif json.Unmarshal(b, &raw) == nil && raw.Version != 1 {\n    return fmt.Errorf(\"unsupported TSDB meta version %d in %s\", raw.Version, bdir)\n}","typeGuard":"func isTSDBMetaV1(raw []byte) bool {\n    var m struct{ Version int `json:\"version\"` }\n    return json.Unmarshal(raw, &m) == nil && m.Version == 1\n}","tryCatchPattern":"m, err := metadata.ReadFromDir(ctx, bdir)\nif err != nil {\n    if strings.Contains(err.Error(), \"unexpected meta file version\") {\n        // skip or quarantine incompatible block\n        return nil\n    }\n    return err\n}","preventionTips":["Keep Prometheus/Thanos versions aligned across read and write paths.","Never hand-edit meta.json files in block directories.","Validate block meta version before ingesting external/replicated blocks."],"tags":["go","metadata","version-mismatch","validation"],"backgroundTag":"invalid-enum-value","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"}