golang/go · error
%s (in %s): %w
Error message
%s (in %s): %w
What it means
Wraps a parse error from `modfile.Parse("go.mod", data, nil)` on the fetched go.mod bytes. The target module's published go.mod is syntactically invalid or contains a construct the parser rejects (unclosed parentheses, bad directive, malformed version). This is a defect in the published module, not in the user's command.
Source
Thrown at src/cmd/go/internal/load/pkg.go:3452
qrs, err := modload.QueryPackages(ld, ctx, patterns[0], version, noneSelected, allowed)
if err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
}
rootMod := qrs[0].Mod
deprecation, err := modload.CheckDeprecation(ld, ctx, rootMod)
if err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
}
if deprecation != "" {
fmt.Fprintf(os.Stderr, "go: module %s is deprecated: %s\n", rootMod.Path, modload.ShortMessage(deprecation, ""))
}
data, err := ld.Fetcher().GoMod(ctx, rootMod.Path, rootMod.Version)
if err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
}
f, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return nil, fmt.Errorf("%s (in %s): %w", args[0], rootMod, err)
}
directiveFmt := "%s (in %s):\n" +
"\tThe go.mod file for the module providing named packages contains one or\n" +
"\tmore %s directives. It must not contain directives that would cause\n" +
"\tit to be interpreted differently than if it were the main module."
if len(f.Replace) > 0 {
return nil, fmt.Errorf(directiveFmt, args[0], rootMod, "replace")
}
if len(f.Exclude) > 0 {
return nil, fmt.Errorf(directiveFmt, args[0], rootMod, "exclude")
}
// Since we are in NoRoot mode, the build list initially contains only
// the dummy command-line-arguments module. Add a requirement on the
// module that provides the packages named on the command line.
if _, err := modload.EditBuildList(ld, ctx, nil, []module.Version{rootMod}); err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
}View on GitHub (pinned to b6b368adc5)
Solutions
- Pin to a different version of the module known to have a valid go.mod.
- Report the broken go.mod to the module maintainer.
- Clear the module cache (`go clean -modcache`) in case the cached .mod is corrupt.
- Upgrade your Go toolchain in case the directive is valid but newer than your version.
Defensive patterns
Strategy: fallback
Validate before calling
// Before committing to a version, check its go.mod parses.
func verifyGoMod(mod, ver string) error {
cmd := exec.Command("go", "mod", "download", "-json", mod+"@"+ver)
out, err := cmd.Output()
if err != nil { return err }
var info struct{ GoMod string }
return json.Unmarshal(out, &info)
} Prevention
- Pin to versions you have validated rather than `@latest` in production scripts.
- Validate a module's go.mod in CI before promoting it as a dependency.
- Report parse errors upstream so the maintainer can retag.
When it happens
Trigger: The module author published a version whose go.mod has malformed syntax — unclosed require block, invalid token, or a directive `modfile.Parse` does not understand under the current toolchain.
Common situations: Module maintainer shipped a broken go.mod; tooling version skew (older go.mod feature not parseable by an older toolchain); corrupted proxy cache.
Related errors
- module requires Go ${p.Module.GoVersion} or later
- %s: argument must be a clean package path
- %s: argument must not be a package in the standard library
- %s: %w
- %s (in %s): The go.mod file for the module providing named
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/43291820bca37d4e.
Report an issue: GitHub.