Jguer/yay · error

failed to open vcs file

Error message

failed to open vcs file '%s': %w

What it means

Returned by `InfoStore.Load` when `os.Open` on the vcs JSON file fails with an error other than NotExist. NotExist is tolerated (empty store), but e.g. permission errors or I/O errors are wrapped with the file path.

Solutions

  1. Fix permissions/ownership on the vcs file path shown in the message (`ls -l`, `chown`).
  2. If the file is corrupt or unnecessary, delete it — the store is recreated when missing.
  3. Check that the path is a regular file, not a directory.
Defensive patterns

Strategy: try-catch

Validate before calling

if info, err := os.Stat(vcsFilePath); err == nil && !info.Mode().IsRegular() {
    return fmt.Errorf("%s is not a regular file", vcsFilePath)
}

Try / catch

store := vcs.NewInfoStore(path)
if err := store.Load(); err != nil {
    if errors.Is(err, fs.ErrPermission) {
        // fix perms or delete the file and continue with an empty store
    }
    return err
}

Prevention

When it happens

Trigger: Opening `<vcs-file-path>` (the persisted vcs info store) fails with EACCES, EISDIR, or an I/O error; only `os.IsNotExist(err)` bypasses this error.

Common situations: Running as a different user than whoever created the vcs file (root vs user cache dirs), the path being a directory, read-only or failing filesystem.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/fabd590215d752b6. Report an issue: GitHub.

Appendix: source

Thrown at pkg/vcs/vcs.go:307

		if _, ok := v.OriginsByPackage[pkgName]; ok {
			delete(v.OriginsByPackage, pkgName)

			updated = true
		}
	}

	if updated {
		if err := v.Save(); err != nil {
			fmt.Fprintln(os.Stderr, err)
		}
	}
}

// LoadStore reads a json file and populates a InfoStore structure.
func (v *InfoStore) Load() error {
	vfile, err := os.Open(v.FilePath)
	if !os.IsNotExist(err) && err != nil {
		return fmt.Errorf("failed to open vcs file '%s': %w", v.FilePath, err)
	}

	defer vfile.Close()

	if !os.IsNotExist(err) {
		decoder := json.NewDecoder(vfile)
		if err = decoder.Decode(&v.OriginsByPackage); err != nil {
			return fmt.Errorf("failed to read vcs '%s': %w", v.FilePath, err)
		}
	}

	return nil
}

func (v *InfoStore) CleanOrphans(pkgs map[string]alpm.Package) {
	missing := make([]string, 0)

	for pkgName := range v.OriginsByPackage {

View on GitHub (pinned to 328f4b4939)