Skip to content

Commit

Permalink
Fix go mod download output expectation for errors (#1442)
Browse files Browse the repository at this point in the history
As per https://go.dev/ref/mod#go-mod-download `type Module struct` has a
`string` field `Error` not a wrapper struct one (unlike `go list -m`
which has a wrapping `*ModuleError`).
  • Loading branch information
illicitonion committed Feb 10, 2023
1 parent af02161 commit 16616f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 1 addition & 3 deletions language/go/update_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ definitely.doesnotexist/ever v0.1.0/go.mod h1:HI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqw
return []byte(`{
"Path": "definitely.doesnotexist/ever",
"Version": "0.1.0",
"Error": {
"Err": "Did not exist"
}
"Error": "Did not exist"
}`), fmt.Errorf("failed to download")
},
}, {
Expand Down
10 changes: 3 additions & 7 deletions language/go/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ type moduleError struct {
Err string
}

type downloadError struct {
Err string
}

// moduleFromDownload is an abstraction to preserve the output of `go mod download`.
// The output schema is documented at https://go.dev/ref/mod#go-mod-download
type moduleFromDownload struct {
Expand All @@ -74,7 +70,7 @@ type moduleFromDownload struct {
Replace *struct {
Path, Version string
}
Error *downloadError
Error string
}

// extractModules lists all modules except for the main module,
Expand Down Expand Up @@ -136,8 +132,8 @@ func fillMissingSums(pathToModule map[string]*moduleFromList) (map[string]*modul
err = fmt.Errorf("%w\nError parsing module for more error information: %v", err, decodeErr)
break
}
if dl.Error != nil {
err = fmt.Errorf("%w\nError downloading %v: %v", err, dl.Path, dl.Error.Err)
if dl.Error != "" {
err = fmt.Errorf("%w\nError downloading %v: %v", err, dl.Path, dl.Error)
}
}
err = fmt.Errorf("error from go mod download: %w", err)
Expand Down

0 comments on commit 16616f8

Please sign in to comment.