golang/go · error
parsing %s: %v
Error message
parsing %s: %v
What it means
Thrown by ListModules (list.go:59) when parsing the reuse file — a JSON stream of modinfo.ModulePublic records used to cache prior 'go list -m' output for incremental reuse. A json.NewDecoder reads the file record-by-record; any decode error that is not io.EOF is wrapped with the reuse file path. The reuse file is passed by the caller as the reuseFile parameter.
Source
Thrown at src/cmd/go/internal/modload/list.go:59
// along with any error preventing additional matches from being identified.
//
// The returned slice can be nonempty even if the error is non-nil.
func ListModules(ld *Loader, ctx context.Context, args []string, mode ListMode, reuseFile string) ([]*modinfo.ModulePublic, error) {
var reuse map[module.Version]*modinfo.ModulePublic
if reuseFile != "" {
data, err := os.ReadFile(reuseFile)
if err != nil {
return nil, err
}
dec := json.NewDecoder(bytes.NewReader(data))
reuse = make(map[module.Version]*modinfo.ModulePublic)
for {
var m modinfo.ModulePublic
if err := dec.Decode(&m); err != nil {
if err == io.EOF {
break
}
return nil, fmt.Errorf("parsing %s: %v", reuseFile, err)
}
if m.Origin == nil {
continue
}
m.Reuse = true
reuse[module.Version{Path: m.Path, Version: m.Version}] = &m
if m.Query != "" {
reuse[module.Version{Path: m.Path, Version: m.Query}] = &m
}
}
}
rs, mods, err := listModules(ld, ctx, LoadModFile(ld, ctx), args, mode, reuse)
type token struct{}
sem := make(chan token, runtime.GOMAXPROCS(0))
if mode != 0 {
for _, m := range mods {View on GitHub (pinned to b6b368adc5)
Solutions
- Delete or regenerate the reuse cache file — the Go command will rebuild it from scratch.
- Run 'go clean -cache' to clear all cached data if the file path is not obvious.
- If calling ListModules programmatically, pass an empty reuseFile string to skip reuse, or ensure the reuseFile is written atomically.
Example fix
// before — reusing a corrupt cache file go list -m -reuse=/tmp/stale_cache.json all // after — drop the reuse flag or delete the file rm -f /tmp/stale_cache.json go list -m all
Defensive patterns
Strategy: try-catch
Try / catch
// When calling ListModules with a reuseFile, handle parse errors gracefully.
mods, err := modload.ListModules(ld, ctx, args, mode, reuseFile)
if err != nil {
// If the error is a reuse-file parse error, retry without reuse.
if strings.Contains(err.Error(), "parsing ") {
os.Remove(reuseFile)
mods, err = modload.ListModules(ld, ctx, args, mode, "")
}
} Prevention
- Write reuse/cache files atomically (write to temp, then rename) to avoid corruption from interrupted writes.
- Avoid concurrent processes writing to the same reuse file.
- Periodically clean caches with 'go clean -cache' if corruption is suspected.
When it happens
Trigger: The 'go list -m' command (or callers like IDE tooling) is invoked with a reuseFile path that contains malformed, truncated, or non-JSON content. A partial write or crash during a previous run left a corrupt reuse cache file.
Common situations: The Go command's internal cache or a tool's reuse file was corrupted by an interrupted process. Disk issues or manual edits to cache files. Concurrent processes writing to the same reuse file.
Related errors
- not a directory
- not completely extracted
- corrupt index
- decoding go list json: %v
- can't decode input %s: %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/fc714b6808d0f919.
Report an issue: GitHub.