{"record":{"id":"363d7b48137d725c","repo":"golang/go","slug":"reading-go-work-w","errorCode":null,"errorMessage":"reading go.work: %w","messagePattern":"reading go\\.work: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modload/init.go","lineNumber":839,"sourceCode":"\t\tseen[modRoot] = true\n\t\tmodRoots = append(modRoots, modRoot)\n\t}\n\n\tfor _, g := range wf.Godebug {\n\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","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modload/init.go#L821-L857","documentation":"ReadWorkFile could not read the bytes of go.work from disk (fsys.ReadFile failed). The raw I/O error is wrapped with %w under the 'reading go.work:' prefix. This is a filesystem-level failure before any parsing is attempted.","triggerScenarios":"go.work path exists but is unreadable: permission denied, I/O error, broken symlink, or the path is a directory. Triggered when Go detects GO_GOWORK / walks up to find a go.work and then tries to read it.","commonSituations":"Tightened file modes (chmod 000 go.work), a CI step that touch'd go.work without write perms, a symlink to a missing target, an encrypted/sealed filesystem not yet unlocked.","solutions":["Verify the file is readable: 'ls -l go.work' and 'cat go.work'; fix permissions (chmod 644).","If a symlink, ensure its target exists and is readable.","Confirm GO_GOWORK / GOWORK env does not point at a stale or wrong path.","If the file should not be used, unset GO_GOWORK or move/delete it so Go stops trying to read it."],"exampleFix":"// before\n$ go build ./...\n// reading go.work: open /repo/go.work: permission denied\n$ ls -l go.work\n---------- 1 root root 0 ... go.work\n\n// after\n$ chmod 644 go.work\n$ go build ./...","handlingStrategy":"validation","validationCode":"// Ensure go.work is readable before building.\nif fi, err := os.Stat(\"go.work\"); err == nil {\n    if fi.Mode().Perm()&0400 == 0 {\n        return fmt.Errorf(\"go.work not readable: mode %v\", fi.Mode().Perm())\n    }\n    if _, err := os.ReadFile(\"go.work\"); err != nil {\n        return fmt.Errorf(\"go.work unreadable: %w\", err)\n    }\n} else if !os.IsNotExist(err) {\n    return err\n}","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"go\", \"build\", \"./...\").CombinedOutput()\nif err != nil && bytes.Contains(out, []byte(\"reading go.work\")) {\n    // filesystem issue; surface and stop (do not retry without fixing perms/mounts)\n    return fmt.Errorf(\"go.work unreadable, check perms/mount: %s\", out)\n}\nreturn err","preventionTips":["Commit go.work with mode 0644.","In CI, verify the go.work mount is present and readable.","Do not point GO_GOWORK at symlinks with missing targets.","Pre-build: os.ReadFile(\"go.work\") as a sanity check."],"tags":["go-work","filesystem","permissions","io-error","read-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}