{"record":{"id":"47dfa204420394e0","repo":"golang/go","slug":"updating-go-mod-w","errorCode":null,"errorMessage":"updating go.mod: %w","messagePattern":"updating go\\.mod: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":2099,"sourceCode":"\t\t\t// other process.\n\t\t\treturn nil, errNoChange\n\t\t}\n\n\t\tif index != nil && !bytes.Equal(old, index.data) {\n\t\t\t// The contents of the go.mod file have changed. In theory we could add all\n\t\t\t// of the new modules to the build list, recompute, and check whether any\n\t\t\t// module in *our* build list got bumped to a different version, but that's\n\t\t\t// a lot of work for marginal benefit. Instead, fail the command: if users\n\t\t\t// want to run concurrent commands, they need to start with a complete,\n\t\t\t// consistent module definition.\n\t\t\treturn nil, fmt.Errorf(\"existing contents have changed since last read\")\n\t\t}\n\n\t\treturn updatedGoMod, nil\n\t})\n\n\tif err != nil && err != errNoChange {\n\t\treturn fmt.Errorf(\"updating go.mod: %w\", err)\n\t}\n\treturn nil\n}\n\n// keepSums returns the set of modules (and go.mod file entries) for which\n// checksums would be needed in order to reload the same set of packages\n// loaded by the most recent call to LoadPackages or ImportFromFiles,\n// including any go.mod files needed to reconstruct the MVS result\n// or identify go versions,\n// in addition to the checksums for every module in keepMods.\nfunc keepSums(ld *Loader, ctx context.Context, pld *packageLoader, rs *Requirements, which whichSums) map[module.Version]bool {\n\t// Every module in the full module graph contributes its requirements,\n\t// so in order to ensure that the build list itself is reproducible,\n\t// we need sums for every go.mod in the graph (regardless of whether\n\t// that version is selected).\n\tkeep := make(map[module.Version]bool)\n\n\t// Add entries for modules in the build list with paths that are prefixes of","sourceCodeStart":2081,"sourceCodeEnd":2117,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L2081-L2117","documentation":"Generic wrapper emitted when the committed go.mod update transaction failed for any reason other than errNoChange. The original error (commonly error 1076, but also lock failures, I/O write errors) is wrapped with %w under 'updating go.mod:'. This is the user-facing top of the update error chain.","triggerScenarios":"modload commits the go.mod rewrite closure and the returned err is non-nil and not errNoChange. Most often the inner error is 'existing contents have changed since last read' (1076); can also be fsync/write permission errors.","commonSituations":"Same as 1076 plus read-only filesystems, full disk, antivirus locking go.mod on Windows, or a held lock by another process.","solutions":["Unwrap the inner error to find the root cause (most often 1076 -> serialize commands).","Ensure the module directory is writable and not locked by AV / IDE.","Free disk space / inode quota if write failed due to ENOSPC.","Re-run after resolving the root cause; the transaction is atomic so no partial write remains."],"exampleFix":"// before\n$ go build ./...\n// updating go.mod: existing contents have changed since last read\n\n// after (resolve the inner cause)\n$ pkill -f 'go mod'   // stop the concurrent writer\n$ go build ./...","handlingStrategy":"try-catch","validationCode":"// Ensure go.mod is writable and not locked before building.\nfi, err := os.Stat(\"go.mod\")\nif err != nil { return err }\nif fi.Mode().Perm()&0200 == 0 {\n    return errors.New(\"go.mod not writable; updates will fail\")\n}\n// also ensure no other writer holds it (advisory lock check omitted for brevity)","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"updating go.mod:\")) {\n    // unwrap inner cause to route recovery\n    inner := strings.TrimSpace(strings.TrimPrefix(string(out), \"updating go.mod:\"))\n    switch {\n    case strings.Contains(inner, \"existing contents have changed\"):\n        // serialize and retry once\n        out, err = exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\n    case strings.Contains(inner, \"permission denied\"):\n        return fmt.Errorf(\"go.mod not writable: %s\", inner)\n    default:\n        return fmt.Errorf(\"go.mod update failed: %s\", inner)\n    }\n}\nreturn err","preventionTips":["Keep go.mod writable (0644) and not held by AV/IDE locks.","Serialize go commands that touch go.mod.","Free disk/inodes so writes succeed.","Read the wrapped inner error before retrying; never retry unchanged."],"tags":["go-mod","update","wrapper","concurrency","io-error"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}