{"record":{"id":"008c1e04cc22428b","repo":"golang/go","slug":"directory-v-does-not-exist","errorCode":null,"errorMessage":"directory %v does not exist","messagePattern":"directory (.+?) does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/workcmd/use.go","lineNumber":138,"sourceCode":"\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}\n\t\t\tsw.Error(err)\n\t\t\tcontinue\n\t\t} else if !info.IsDir() {\n\t\t\tsw.Error(fmt.Errorf(\"%s is not a directory\", base.ShortPath(absArg)))\n\t\t\tcontinue\n\t\t}\n\n\t\tif !*useR {\n\t\t\tlookDir(useDir)\n\t\t\tcontinue\n\t\t}\n\n\t\t// Add or remove entries for any subdirectories that still exist.\n\t\t// If the root itself is a symlink to a directory,\n\t\t// we want to follow it (see https://go.dev/issue/50807).\n\t\t// Add a trailing separator to force that to happen.\n\t\tfsys.WalkDir(str.WithFilePathSeparator(useDir), func(path string, d fs.DirEntry, err error) error {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/workcmd/use.go#L120-L156","documentation":"Thrown by `go work use` when fsys.Stat fails on a user-supplied path and os.IsNotExist is true. The command walks each argument with pathRel, stats the absolute path, and rewrites a raw os.Stat error into this friendly message via base.ShortPath. It is purely a path-existence check before the directory is considered for the go.work use directive.","triggerScenarios":"Running `go work use <path>` (or `go work use -r <path>`) where <path> does not resolve to anything on disk. The loop at use.go:131 calls fsys.Stat(absArg); a non-existent absArg yields ENOENT and this error is reported through sw.Error.","commonSituations":"Typos in the directory argument, running `go work use` from the wrong working directory, relative paths that assume a different cwd, paths that were deleted/moved between shell tab-completion and command execution, or symlinks pointing at removed targets.","solutions":["Verify the path exists: `ls -la <path>` or `test -d <path>` before re-running.","Check your current working directory and use an absolute path or correct relative path.","If the directory was deleted intentionally, remove the corresponding `use` directive from go.work manually or run `go work edit -dropuse=<path>`.","Recreate the directory if it should exist (e.g. `mkdir -p <path>` and ensure it contains a go.mod)."],"exampleFix":"// before\ngo work use ./mymoddule // typo\n\n// after\ngo work use ./mymodule","handlingStrategy":"validation","validationCode":"// before `go work use <p>`:\ninfo, err := os.Stat(p)\nif err != nil || !info.IsDir() {\n    log.Fatalf(\"%s is not an existing directory\", p)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve paths to absolute form before passing to `go work use`.","Validate directories with os.Stat + IsDir in scripts that build go.work.","Run `go work use` from a fixed cwd (the go.work root) to keep relative paths stable."],"tags":["go-work","filesystem","cli","path-validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}