{"record":{"id":"4b1259e77af63157","repo":"dagger/dagger","slug":"failed-to-write-updated-parent-go-mod-w","errorCode":null,"errorMessage":"failed to write updated parent go.mod: %w","messagePattern":"failed to write updated parent go\\.mod: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/generate_client.go","lineNumber":174,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to find parent go.mod: %w\", err)\n\t\t}\n\n\t\t// Check if parent go.mod is at OutputDir or above it\n\t\t// If at OutputDir, we can write directly to overlay\n\t\t// If above OutputDir, we can't write to overlay (would be outside OutputDir), so skip this\n\t\tif parentGoModDir == g.Config.OutputDir {\n\t\t\t// Add require and replace to parent's go.mod\n\t\t\tgoModFile.AddRequire(clientModuleName, \"v0.0.0\")\n\t\t\tgoModFile.AddReplace(clientModuleName, \"\", \"./\"+clientRelPath, \"\")\n\n\t\t\tupdatedParentGoMod, err := goModFile.Format()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to format parent go.mod: %w\", err)\n\t\t\t}\n\n\t\t\tif err := mfs.WriteFile(\"go.mod\", updatedParentGoMod, 0600); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to write updated parent go.mod: %w\", err)\n\t\t\t}\n\t\t}\n\t\t// If parent go.mod is outside OutputDir, we can't update it via overlay\n\t\t// The user will need to manually add require/replace directives\n\t}\n\n\t// We intentionally do not run `go mod tidy` here. The client go.mod pins\n\t// `dagger.io/dagger` at the engine version, which in a dev environment is\n\t// not yet published, so tidy would fail resolving it against the module\n\t// proxy before a replace directive is in place. Tidy is left to the caller\n\t// (who supplies the replace, or resolves against a real proxy once the\n\t// version is released / served by the dev harness).\n\t//\n\t// Note: We also don't run go mod tidy on the parent here because it would\n\t// remove the require directive if the parent doesn't actually import the\n\t// client yet. The user should run go mod tidy on the parent when ready.\n\n\treturn g.generatedClientState(layerfs.New(layers...), postCmds...)","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/generate_client.go#L156-L192","documentation":"Once the parent go.mod formats successfully, it is written to the in-memory overlay at path \"go.mod\" (parent module root == OutputDir). A WriteFile failure is wrapped here. Generation aborts after the client code was produced but before the parent module update lands.","triggerScenarios":"isInstall==true, parent go.mod at OutputDir, and mfs.WriteFile(\"go.mod\", updatedParentGoMod, 0600) returns an error. Raised at generate_client.go:174.","commonSituations":"Overlay path collision (something else already wrote go.mod into the overlay at a conflicting state), or an internal memfs inconsistency after earlier generation steps.","solutions":["Inspect the inner wrapped error for the memfs root cause","Re-run `dagger generate` from a clean state (no stale overlay artifacts)","If it persists, manually add the require/replace lines to your go.mod: require <client module> v0.0.0 and replace <client module> => ./<client rel path>","File an issue if reproducible, since OutputDir==parent go.mod is the supported fast path"],"exampleFix":"// manual fallback in parent go.mod\nrequire example.com/myproject/client v0.0.0\nreplace example.com/myproject/client => ./dagger\n","handlingStrategy":"try-catch","validationCode":"// parent go.mod must equal OutputDir for overlay write; verify before\ngoModData, err := os.ReadFile(\"go.mod\")\nif err != nil {\n\treturn fmt.Errorf(\"parent go.mod unreadable: %w\", err)\n}\nif _, err := modfile.Parse(\"go.mod\", goModData, nil); err != nil {\n\treturn fmt.Errorf(\"parent go.mod invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"state, err := gen.GenerateClient(ctx, schema, schemaVersion)\nif err != nil && strings.Contains(err.Error(), \"failed to write updated parent go.mod\") {\n\t// fallback: add directives manually\n\t// require <client module> v0.0.0\n\t// replace <client module> => ./<client dir>\n\treturn err\n}","preventionTips":["Run generation from the module root so OutputDir matches parent go.mod","Know the manual fallback: add require/replace lines yourself if overlay write fails","Report reproducible failures since this is the supported install path"],"tags":["go","go-mod","codegen","filesystem"],"backgroundTag":"go-mod-write-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}