{"record":{"id":"a360fe6581d2272e","repo":"golang/go","slug":"v-is-not-a-regular-file","errorCode":null,"errorMessage":"%v is not a regular file","messagePattern":"(.+?) is not a regular file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/workcmd/use.go","lineNumber":121,"sourceCode":"\t// lookDir updates the entry in keepDirs for the directory dir,\n\t// which is either absolute or relative to the current working directory\n\t// (not necessarily the directory containing the workfile).\n\tlookDir := func(dir string) {\n\t\tabsDir, dir := pathRel(workDir, dir)\n\n\t\tfile := filepath.Join(absDir, \"go.mod\")\n\t\tfi, err := fsys.Stat(file)\n\t\tif err != nil {\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\tkeepDirs[absDir] = \"\"\n\t\t\t} else {\n\t\t\t\tsw.Error(err)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tif !fi.Mode().IsRegular() {\n\t\t\tsw.Error(fmt.Errorf(\"%v is not a regular file\", base.ShortPath(file)))\n\t\t\treturn\n\t\t}\n\n\t\tif dup := keepDirs[absDir]; dup != \"\" && dup != dir {\n\t\t\tbase.Errorf(`go: already added \"%s\" as \"%s\"`, dir, dup)\n\t\t}\n\t\tkeepDirs[absDir] = dir\n\t}\n\n\tfor _, useDir := range args {\n\t\tabsArg, _ := pathRel(workDir, useDir)\n\n\t\tinfo, err := fsys.Stat(absArg)\n\t\tif err != nil {\n\t\t\t// Errors raised from os.Stat are formatted to be more user-friendly.\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\terr = fmt.Errorf(\"directory %v does not exist\", base.ShortPath(absArg))\n\t\t\t}","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/workcmd/use.go#L103-L139","documentation":"Thrown by lookDir (during `go work use`) when a candidate directory's go.mod exists but is not a regular file — it is a symlink to nowhere, a directory, a device, a pipe, etc. The go command requires go.mod to be a genuine regular file before adding the directory to the workfile.","triggerScenarios":"Run `go work use ./mymod` where `./mymod/go.mod` is a broken symlink, a directory (someone ran `mkdir go.mod`), or some other non-regular filesystem entry. fsys.Stat succeeds but fi.Mode().IsRegular() is false, so lookDir reports the error via ShortPath.","commonSituations":"A broken symlink left by a failed `ln -s`; go.mod accidentally created as a directory; a FUSE bind mount presenting go.mod oddly; a git submodule checkout where go.mod is a sparse-checkout placeholder; tooling that replaced go.mod with a fifo/socket.","solutions":["Inspect the entry: `ls -l ./mymod/go.mod` and `file ./mymod/go.mod`.","If it is a broken symlink, remove it and recreate the file (e.g. `rm go.mod && go mod init`).","If go.mod is a directory, rename it and run `go mod init`.","Re-clone the module/repository if the entry is corrupt."],"exampleFix":"# before\n// ls -l mymod/go.mod  -> symlink to nonexistent\n\n# after\n// rm mymod/go.mod && (cd mymod && go mod init example.com/mymod)","handlingStrategy":"validation","validationCode":"// Verify go.mod is a regular file before `go work use`\ngoMod := filepath.Join(dir, \"go.mod\")\nfi, err := os.Lstat(goMod)\nif err != nil { log.Fatalf(\"go.mod missing: %v\", err) }\nif !fi.Mode().IsRegular() {\n    log.Fatalf(\"%s is not a regular file (mode %s)\", goMod, fi.Mode())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not symlink go.mod across module boundaries.","Never create go.mod as a directory.","Re-clone corrupt submodules before `go work use`."],"tags":["go-toolchain","work","modules","filesystem","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}