gohugoio/hugo · error
failed to get %q: %w
Error message
failed to get %q: %w
What it means
Returned by Hugo's module Client.get when `go get <args>` fails. Hugo shells out to the Go toolchain to add or update module dependencies (e.g. via `hugo mod get`), and this wraps any non-zero exit from that command with the arguments that were passed.
Source
Thrown at modules/client.go:358
} else if update && patch {
args = append(args, "-u=patch")
}
args = append(args, m)
if err := c.get(args...); err != nil {
return err
}
}
return nil
}
return c.get(args...)
}
func (c *Client) get(args ...string) error {
if err := c.runGo(context.Background(), c.logger.StdOut(), append([]string{"get"}, args...)...); err != nil {
return fmt.Errorf("failed to get %q: %w", args, err)
}
return nil
}
// Init initializes this as a Go Module with the given path.
// If path is empty, Go will try to guess.
// If this succeeds, this project will be marked as Go Module.
func (c *Client) Init(path string) error {
err := c.runGo(context.Background(), c.logger.StdOut(), "mod", "init", path)
if err != nil {
return fmt.Errorf("failed to init modules: %w", err)
}
c.GoModulesFilename = filepath.Join(c.ccfg.WorkingDir, goModFilename)
return nil
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Verify the module path and version exist (`go list -m -versions <path>`).
- Run `hugo mod init <path>` first if the project has no go.mod.
- For private repos, set GOPRIVATE and configure git credentials.
- Check network/proxy access to proxy.golang.org or set GOPROXY.
- Upgrade the Go toolchain if the error mentions an unsupported go version.
Example fix
# before hugo mod get github.com/user/theme-typo # after hugo mod init github.com/me/mysite hugo mod get github.com/user/theme@v1.2.0
Defensive patterns
Strategy: validation
Validate before calling
// verify module path is well-formed before calling Get
if err := module.CheckPath(modPath); err != nil {
return fmt.Errorf("invalid module path %q: %w", modPath, err)
} Try / catch
if err := client.Get(modPath); err != nil {
var execErr *exec.ExitError
if errors.As(err, &execErr) {
// go mod get failed — inspect stderr, likely bad path/version or network
}
return err
} Prevention
- Validate module paths with golang.org/x/mod/module.CheckPath before invoking Get
- Ensure the go binary is on PATH and GOPROXY/GONOSUMCHECK env is configured before client construction
- Pin explicit versions (path@vX.Y.Z) instead of @latest to avoid resolution surprises
- Check network/proxy reachability (GOPROXY endpoint) in a preflight step for CI environments
When it happens
Trigger: Running `hugo mod get [-u] <module>` or Client.Get when `go get` exits non-zero: unresolvable module path, no matching version, network/proxy failure, missing go.mod in the project, or a Go binary too old for the module's go directive.
Common situations: Typos in module paths in `hugo mod get`, private repos without GOPRIVATE/credentials configured, corporate proxies blocking proxy.golang.org, running outside a directory initialized with `hugo mod init`, or an outdated Go installation.
Related errors
- failed to download module %s@%s: %w
- failed to decode module download result: %w
- failed to download modules: %w
- failed to decode modules list: %w
- failed to init modules: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/e507b7bf259eda65.json.
Report an issue: GitHub ↗.