{"record":{"id":"5a8cbae4f11fbd7c","repo":"github/copilot-sdk","slug":"failed-to-read-package-directory-q-w","errorCode":null,"errorMessage":"failed to read package directory %q: %w","messagePattern":"failed to read package directory %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"go/cmd/bundler/main.go","lineNumber":217,"sourceCode":"func validPlatforms() []string {\n\tresult := make([]string, 0, len(platforms))\n\tfor p := range platforms {\n\t\tresult = append(result, p)\n\t}\n\treturn result\n}\n\n// detectPackageName reads package clauses from files that match the target\n// platform and build constraints. It returns defaultPackageName with an error\n// when detection fails.\nfunc detectPackageName(dir, goos, goarch string) (string, error) {\n\tif dir == \"\" {\n\t\tdir = \".\"\n\t}\n\n\tentries, err := os.ReadDir(dir)\n\tif err != nil {\n\t\treturn defaultPackageName, fmt.Errorf(\"failed to read package directory %q: %w\", dir, err)\n\t}\n\n\tbuildContext := build.Default\n\tbuildContext.GOOS = goos\n\tbuildContext.GOARCH = goarch\n\n\tpackageName := \"\"\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tif entry.IsDir() || !strings.HasSuffix(name, \".go\") ||\n\t\t\tstrings.HasPrefix(name, \".\") || strings.HasPrefix(name, \"_\") ||\n\t\t\tstrings.HasSuffix(name, \"_test.go\") || strings.HasPrefix(name, \"zcopilot_\") {\n\t\t\tcontinue\n\t\t}\n\t\tmatches, err := buildContext.MatchFile(dir, name)\n\t\tif err != nil {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"failed to evaluate build constraints in %q: %w\", filepath.Join(dir, name), err)\n\t\t}","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L199-L235","documentation":"detectPackageName reads the package directory to infer the main package name for bundling; this error wraps an os.ReadDir failure, falling back to defaultPackageName. It indicates the directory could not be read at all (missing, not a directory, or permission problem).","triggerScenarios":"detectPackageName (called from main) invokes os.ReadDir on the configured or default ('.') directory and the OS returns an error, e.g. the package dir flag points to a nonexistent or unreadable path.","commonSituations":"Typo in the --dir/package directory flag; running the bundler from the wrong working directory; the source directory was deleted or renamed; insufficient filesystem permissions (CI containers, read-only mounts).","solutions":["Verify the directory path exists and is readable (ls <dir>) before running the bundler.","Run the bundler from the Go module root, or pass the correct package directory flag.","Fix filesystem permissions (chmod/chown) or run in an environment that can read the path.","Check the wrapped OS error in the message to distinguish 'no such file or directory' from 'permission denied'."],"exampleFix":"// before\nbundler --platform linux/amd64 --dir ./cmd/typo\n\n// after\nbundler --platform linux/amd64 --dir ./cmd/app","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(dir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"package directory %q not readable: %v\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"failed to read package directory\") {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) {\n        log.Fatalf(\"check path/permissions for %s: %v\", pathErr.Path, pathErr.Err)\n    }\n}","preventionTips":["Verify the directory exists with os.Stat before bundling.","Run the bundler from the module root or pass absolute paths.","Ensure the CI/user has read access to the source tree."],"tags":["filesystem","directory","cli","go"],"backgroundTag":"file-read-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}