golang/go · error

parsing %s: %v

Error message

parsing %s: %v

What it means

Returned from rawGoModSummary when modfile.ParseLax fails on a dependency's go.mod file (the bytes fetched from the proxy or read from a replacement). It is wrapped in module.VersionError so the offending module@version is identified. ParseLax is lenient (it permits missing go directives), so failure here means a structurally broken go.mod.

Source

Thrown at src/cmd/go/internal/modload/modfile.go:718

		// command-line-arguments module, which rawGoModData cannot read a go.mod for.
		return &modFileSummary{module: m}, nil
	} else if m.Version == "" && ld.inWorkspaceMode() && ld.MainModules.Contains(m.Path) {
		// When go get uses EnterWorkspace to check that the workspace loads properly,
		// it will update the contents of the workspace module's modfile in memory. To use the updated
		// contents of the modfile when doing the load, don't read from disk and instead
		// recompute a summary using the updated contents of the modfile.
		if mf := ld.MainModules.ModFile(m); mf != nil {
			return summaryFromModFile(m, ld.MainModules.modFiles[m])
		}
	}
	return rawGoModSummaryCache.Do(m, func() (*modFileSummary, error) {
		name, data, err := rawGoModData(ld, m)
		if err != nil {
			return nil, err
		}
		f, err := modfile.ParseLax(name, data, nil)
		if err != nil {
			return nil, module.VersionError(m, fmt.Errorf("parsing %s: %v", base.ShortPath(name), err))
		}
		return summaryFromModFile(m, f)
	})
}

func summaryFromModFile(m module.Version, f *modfile.File) (*modFileSummary, error) {
	summary := new(modFileSummary)
	if f.Module != nil {
		summary.module = f.Module.Mod
		summary.deprecated = f.Module.Deprecated
	}
	if f.Go != nil {
		rawGoVersion.LoadOrStore(m, f.Go.Version)
		summary.goVersion = f.Go.Version
		summary.pruning = pruningForGoVersion(f.Go.Version)
	} else {
		summary.pruning = unpruned
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Read the file:line in the wrapped error to locate the syntax problem in the dependency's go.mod.
  2. If it is a replace target you control, fix the go.mod syntax there.
  3. Upgrade or downgrade the offending module to a version with a valid go.mod: 'go get <module>@<known-good-version>'.
  4. Clear the cache and retry: 'go clean -modcache' (forces re-download).

Example fix

// before
// error: parsing go.mod: example.com/bad@v1.0.0/go.mod:3: unknown directive 'dep'

// after: pin a known-good version or fix the replaced file
$ go get example.com/bad@v0.9.0
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-validate that a dependency's go.mod is parseable before adding it:
//   go mod download <module>@<version>
//   go list -m -json <module>@<version>  // fails if go.mod is corrupt

Try / catch

// When resolving the graph, isolate a single bad module without failing the whole build:
//   for _, m := range modules {
//       if _, err := rawGoModSummary(ld, m); err != nil {
//           if strings.Contains(err.Error(), "parsing") { badMods = append(badMods, m); continue }
//           return err
//       }
//   }

Prevention

When it happens

Trigger: Resolving the module graph for a dependency whose published go.mod is malformed: unclosed parentheses, bad quoting, unknown directive tokens, or invalid version syntax that even lax parsing rejects.

Common situations: A module author published a corrupt go.mod (bad tag, truncated upload); a module proxy served partial/corrupt content; a replace points at a hand-edited go.mod with a syntax error; tampered cache.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/284ee65824db202a. Report an issue: GitHub.