Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Avoid global state at (almost) all cost.
* This is a project with a long history; assume that a similiar problem has been solved before, look hard for helper functions before creating new ones.
* In tests, use `qt` matchers (e.g. `b.Assert(err, qt.ErrorMatches, ...)`) instead of raw `if`/`t.Fatal` checks.
* Brevity is good. This applies to code, comments and commit messages. Don't write a novel.
* Use `./check.sh ./somepackage/...` when iterating.
* Use `./check.sh` when you're done.

Expand Down
23 changes: 23 additions & 0 deletions hugolib/hugo_modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,29 @@ Home: {{ .Title }}|{{ .Content }}|
b.AssertFileContent("public/index.html", "Home: |<h1 id=\"hello-world\">Hello World</h1>\n|")
}

// https://github.com/gohugoio/hugo/issues/14543
func TestModulePrivateRepo(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
baseURL = "https://example.com/"
[module]
[[module.imports]]
path = "github.com/bep/this-is-a-non-existing-repo"
version = "main"
[[module.imports.mounts]]
source = "content"
target = "content"
-- layouts/all.html --
Title: {{ .Title }}|
List: {{ .Title }}
`

b, err := TestE(t, files, TestOptOsFs())
b.Assert(err, qt.ErrorMatches, `(?s).*mod download.*invalid version.*repository.*`)
}

// https://github.com/gohugoio/hugo/issues/6299
func TestSiteWithGoModButNoModules(t *testing.T) {
t.Parallel()
Expand Down
17 changes: 17 additions & 0 deletions modules/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ func (c *Client) downloadModuleVersion(path, version string) (*goModule, error)
b := &bytes.Buffer{}
err := c.runGo(context.Background(), b, args...)
if err != nil {
// The -json flag makes Go output error details as JSON to stdout
// even on failure. Try to extract the error message from the JSON output.
if jsonErr := extractGoModDownloadError(b.Bytes()); jsonErr != "" {
return nil, fmt.Errorf("failed to download module %s@%s: %s: %s", path, version, err, jsonErr)
}
return nil, fmt.Errorf("failed to download module %s@%s: %w", path, version, err)
}

Expand Down Expand Up @@ -965,6 +970,18 @@ type goModuleError struct {
Err string // the error itself
}

func extractGoModDownloadError(b []byte) string {
// go mod download -json outputs Error as a plain string,
// unlike go list -m -json which uses {"Err": "..."}.
var m struct {
Error string
}
if err := json.Unmarshal(b, &m); err == nil && m.Error != "" {
return m.Error
}
return ""
}

type goModules []*goModule

type modSum struct {
Expand Down
Loading