{"record":{"id":"e98d3466a2cd396e","repo":"thanos-io/thanos","slug":"failed-to-read-s","errorCode":null,"errorMessage":"failed to read %s","messagePattern":"failed to read (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/shipper/shipper.go","lineNumber":653,"sourceCode":"\t\trunutil.CloseWithLogOnErr(logger, f, \"write meta file close\")\n\t\treturn err\n\t}\n\n\t// Force the kernel to persist the file on disk to avoid data loss if the host crashes.\n\tif err := f.Sync(); err != nil {\n\t\treturn err\n\t}\n\tif err := f.Close(); err != nil {\n\t\treturn err\n\t}\n\treturn renameFile(logger, tmp, path)\n}\n\n// ReadMetaFile reads the given meta from <dir>/thanos.shipper.json.\nfunc ReadMetaFile(path string) (*Meta, error) {\n\tb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to read %s\", path)\n\t}\n\n\tvar m Meta\n\tif err := json.Unmarshal(b, &m); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to parse %s as JSON: %q\", path, string(b))\n\t}\n\tif m.Version != MetaVersion1 {\n\t\treturn nil, errors.Errorf(\"unexpected meta file version %d\", m.Version)\n\t}\n\n\treturn &m, nil\n}\n\nfunc renameFile(logger log.Logger, from, to string) error {\n\tif err := os.RemoveAll(to); err != nil {\n\t\treturn err\n\t}\n\tif err := os.Rename(from, to); err != nil {","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/shipper/shipper.go#L635-L671","documentation":"ReadMetaFile reads the shipper's bookkeeping file thanos.shipper.json from the given path via os.ReadFile. If the file cannot be read (missing, permission denied, I/O error), the error is wrapped with \"failed to read <path>\". The shipper stores the list of already-uploaded block ULIDs in this file, so callers use it to compute which blocks still need uploading.","triggerScenarios":"Calling UploadedBlocks(), Sync(), or AreAllBlocksUploaded() (and the anonymous iterator wrapper) when <data-dir>/thanos.shipper.json does not exist yet or is unreadable.","commonSituations":"First run against a fresh data directory where the meta file was never written; file deleted by an operator or cleanup job; permission change on the data dir; read-only mount after an incident recovery; running the process as a different UID than the file owner.","solutions":["If the data dir is new, treat this as initialization: on first Sync the shipper writes the meta file — ensure the process can create files in the data dir.","Check permissions on thanos.shipper.json and its directory; chown/chmod so the shipper UID can read it.","Restore the file if it was deleted (or accept re-upload of blocks — safe, as uploads are idempotent — by letting the shipper recreate it).","Verify the mount is not read-only and the path passed to the shipper is correct (the error includes the full path)."],"exampleFix":"// before: assuming meta file always exists\nmeta, _ := shipper.ReadMetaFile(path)\n// after: tolerate a missing file on first run\nmeta, err := shipper.ReadMetaFile(path)\nif os.IsNotExist(errors.Cause(err)) {\n\tmeta = &shipper.Meta{Version: shipper.MetaVersion1}\n}","handlingStrategy":"try-catch","validationCode":"metaPath := filepath.Join(dataDir, \"thanos.shipper.json\")\nif _, err := os.Stat(metaPath); os.IsNotExist(err) {\n\tlevel.Info(logger).Log(\"msg\", \"no shipper meta yet, first run\")\n}","typeGuard":null,"tryCatchPattern":"meta, err := shipper.ReadMetaFile(metaPath)\nif err != nil {\n\tif os.IsNotExist(errors.Cause(err)) {\n\t\tmeta = &shipper.Meta{Version: shipper.MetaVersion1}\n\t} else {\n\t\treturn errors.Wrap(err, \"read shipper meta\")\n\t}\n}","preventionTips":["Ensure the data dir is writable so the shipper can create thanos.shipper.json on first run.","Exclude thanos.shipper.json from cleanup/retention jobs.","Keep the process UID consistent so file permissions remain valid across upgrades.","Persist the data dir across restarts (PVC) so upload bookkeeping is not lost."],"tags":["filesystem","file-not-found","metadata","thanos"],"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"}