{"record":{"id":"4fecdb72bd264dec","repo":"golang/go","slug":"errors-parsing-go-work-w","errorCode":null,"errorMessage":"errors parsing go.work:\n%w","messagePattern":"errors parsing go\\.work:\n%w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":844,"sourceCode":"\t\tif err := CheckGodebug(\"godebug\", g.Key, g.Value); err != nil {\n\t\t\treturn nil, nil, fmt.Errorf(\"error loading go.work:\\n%s:%d: %w\", base.ShortPath(path), g.Syntax.Start.Line, err)\n\t\t}\n\t}\n\n\treturn wf, modRoots, nil\n}\n\n// ReadWorkFile reads and parses the go.work file at the given path.\nfunc ReadWorkFile(path string) (*modfile.WorkFile, error) {\n\tpath = base.ShortPath(path) // use short path in any errors\n\tworkData, err := fsys.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading go.work: %w\", err)\n\t}\n\n\tf, err := modfile.ParseWork(path, workData, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"errors parsing go.work:\\n%w\", err)\n\t}\n\tif f.Go != nil && gover.Compare(f.Go.Version, gover.Local()) > 0 && cfg.CmdName != \"work edit\" {\n\t\tbase.Fatal(&gover.TooNewError{What: base.ShortPath(path), GoVersion: f.Go.Version})\n\t}\n\treturn f, nil\n}\n\n// WriteWorkFile cleans and writes out the go.work file to the given path.\nfunc WriteWorkFile(path string, wf *modfile.WorkFile) error {\n\twf.SortBlocks()\n\twf.Cleanup()\n\tout := modfile.Format(wf.Syntax)\n\n\treturn os.WriteFile(path, out, 0o666)\n}\n\n// UpdateWorkGoVersion updates the go line in wf to be at least goVers,\n// reporting whether it changed the file.","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L826-L862","documentation":"go.work bytes were read but modfile.ParseWork rejected them (syntax/grammar error). The parser error is wrapped with %w under 'errors parsing go.work:'. This is distinct from read failures (1067) and from semantic validation failures (1065, 1066).","triggerScenarios":"go.work contains malformed syntax: unbalanced parens in a 'use ( ... )' block, stray tokens, bad directive verb, missing value, unterminated string. modfile.ParseWork returns a non-nil error and ReadWorkFile wraps it.","commonSituations":"Hand-edited go.work with a typo; merge conflict markers left in the file; a tool that writes partial go.work; copy-paste from docs that introduced smart quotes.","solutions":["Open go.work and fix the syntax at the parser-reported line/column.","Remove git merge conflict markers (<<<<<<< ======= >>>>>>>) if present.","Regenerate with 'go work init ./m1 ./m2 ...' (or 'go work edit') to get a syntactically valid file, then re-apply customizations.","Validate by running 'gofmt -e go.work' or re-running the failing command to see the precise parse location."],"exampleFix":"// before (go.work)\nuse (\n    ./svc-a\n    ./svc-b\n// missing closing paren\n// errors parsing go.work: 4:1: expected ')'\n\n// after\nuse (\n    ./svc-a\n    ./svc-b\n)","handlingStrategy":"validation","validationCode":"// Parse go.work early to catch syntax errors with location.\ndata, err := os.ReadFile(\"go.work\")\nif err != nil && !os.IsNotExist(err) { return err }\nif err == nil {\n    if _, perr := modfile.ParseWork(\"go.work\", data, nil); perr != nil {\n        return fmt.Errorf(\"go.work parse error: %w\", perr)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"errors parsing go.work\")) {\n    // regenerate from known module list rather than guessing the fix\n    return fmt.Errorf(\"go.work malformed; recreate with 'go work init ...': %s\", out)\n}\nreturn err","preventionTips":["Edit go.work only via 'go work edit' to keep syntax valid.","Resolve git merge conflicts in go.work before building.","Lint go.work with gofmt -e in pre-commit.","Avoid smart-quotes / tabs introduced by editors."],"tags":["go-work","parse-error","syntax","modfile"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}