{"record":{"id":"069bdef04c313291","repo":"Jguer/yay","slug":"failed-to-read-vcs-s-w","errorCode":null,"errorMessage":"failed to read vcs '%s': %w","messagePattern":"failed to read vcs '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/vcs/vcs.go","lineNumber":315,"sourceCode":"\t\tif err := v.Save(); err != nil {\n\t\t\tfmt.Fprintln(os.Stderr, err)\n\t\t}\n\t}\n}\n\n// LoadStore reads a json file and populates a InfoStore structure.\nfunc (v *InfoStore) Load() error {\n\tvfile, err := os.Open(v.FilePath)\n\tif !os.IsNotExist(err) && err != nil {\n\t\treturn fmt.Errorf(\"failed to open vcs file '%s': %w\", v.FilePath, err)\n\t}\n\n\tdefer vfile.Close()\n\n\tif !os.IsNotExist(err) {\n\t\tdecoder := json.NewDecoder(vfile)\n\t\tif err = decoder.Decode(&v.OriginsByPackage); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to read vcs '%s': %w\", v.FilePath, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (v *InfoStore) CleanOrphans(pkgs map[string]alpm.Package) {\n\tmissing := make([]string, 0)\n\n\tfor pkgName := range v.OriginsByPackage {\n\t\tif _, ok := pkgs[pkgName]; !ok {\n\t\t\tv.logger.Debugln(\"removing orphaned vcs package:\", pkgName)\n\t\t\tmissing = append(missing, pkgName)\n\t\t}\n\t}\n\n\tv.RemovePackages(missing)\n}","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/Jguer/yay/blob/328f4b4939fb35f38c2f7c7ce3b8638a839bafa5/pkg/vcs/vcs.go#L297-L333","documentation":"Returned by InfoStore.Load when the VCS info JSON file at v.FilePath exists and opens successfully but fails to decode, i.e. json.Decoder.Decode returns an error. The file path and underlying JSON error are wrapped. It means the on-disk vcs.json cache is present but corrupt or not valid JSON for the OriginsByPackage structure.","triggerScenarios":"`decoder.Decode(&v.OriginsByPackage)` errors on the vcs file: truncated file from a crash mid-write, empty/corrupt content, or JSON written by an incompatible older version.","commonSituations":"System crash or power loss during a previous run, disk-full truncating the file, manually edited vcs file with invalid JSON.","solutions":["Delete the vcs file at the reported path — it is a cache and will be recreated on next run.","Inspect the file with `jq` or `json.tool` to confirm it is corrupt before deleting.","Keep backups if the file holds meaningful state; otherwise treat it as disposable cache."],"exampleFix":"rm ~/.cache/yay/vcs.json  # then rerun; store is rebuilt","handlingStrategy":"fallback","validationCode":"if b, err := os.ReadFile(vcsFilePath); err == nil && !json.Valid(b) {\n    // file is corrupt: remove it and let the store rebuild\n    os.Remove(vcsFilePath)\n}","typeGuard":null,"tryCatchPattern":"if err := store.Load(); err != nil {\n    // fall back to empty store after confirming corruption\n    os.Remove(v.FilePath)\n    return store.Load()\n}","preventionTips":["Treat the vcs JSON file as a regenerable cache; delete on corruption","Avoid killing the process mid-write; use filesystem sync for durability","Periodically validate cache JSON files with a parser"],"tags":["vcs","json","corrupt-file","cache"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"328f4b4939fb35f38c2f7c7ce3b8638a839bafa5","analyzedAt":"2026-09-07T16:45:12.608Z","contentChangedAt":"2026-09-07T16:45:12.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}