Skip to content

Commit

Permalink
[cmd/fetch_repo] make cache corruption failures more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-french committed Apr 11, 2024
1 parent 1e0d875 commit 798e787
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cmd/fetch_repo/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ func fetchModule(dest, importpath, version, sum string) error {
if err := json.Unmarshal(buf.Bytes(), &dl); err != nil {
if bufErr.Len() > 0 {
return fmt.Errorf("%s %s: %s", cmd.Path, strings.Join(cmd.Args, " "), bufErr.Bytes())
} else {
return fmt.Errorf("%s %s: %v", cmd.Path, strings.Join(cmd.Args, " "), err)
}
return fmt.Errorf("%s %s: %v", cmd.Path, strings.Join(cmd.Args, " "), err)
}
if dl.Error != "" {
return errors.New(dl.Error)
Expand All @@ -116,18 +115,20 @@ func fetchModule(dest, importpath, version, sum string) error {
}

// Copy the module to the destination.
err = copyTree(dest, dl.Dir)
if err != nil {
if err := copyTree(dest, dl.Dir); err != nil {
return fmt.Errorf("failed copying repo: %w", err)
}

// Verify sum
// Verify sum of the directory itself against the go.sum.
repoSum, err := dirhash.HashDir(dest, importpath+"@"+version, dirhash.Hash1)
if err != nil {
return fmt.Errorf("failed computing sum: %w", err)
}

if repoSum != sum {
if goModCache := os.Getenv("GOMODCACHE"); modcacherw && goModCache != "" {
return fmt.Errorf("resulting module with sum %s; expected sum %s, Please try clearing your module cache directory %q", repoSum, sum, goModCache)
}
return fmt.Errorf("resulting module with sum %s; expected sum %s", repoSum, sum)
}

Expand Down

0 comments on commit 798e787

Please sign in to comment.