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()
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)
}
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 {