{"record":{"id":"1853ac41713f3dff","repo":"github/copilot-sdk","slug":"failed-to-parse-package-clause-in-q-w","errorCode":null,"errorMessage":"failed to parse package clause in %q: %w","messagePattern":"failed to parse package clause in %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":243,"sourceCode":"\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}\n\t\tif !matches {\n\t\t\tcontinue\n\t\t}\n\n\t\tpath := filepath.Join(dir, name)\n\t\tfile, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.PackageClauseOnly)\n\t\tif err != nil {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"failed to parse package clause in %q: %w\", path, err)\n\t\t}\n\n\t\tif packageName == \"\" {\n\t\t\tpackageName = file.Name.Name\n\t\t\tcontinue\n\t\t}\n\t\tif packageName != file.Name.Name {\n\t\t\treturn defaultPackageName, fmt.Errorf(\"multiple packages %q and %q found in %q\", packageName, file.Name.Name, dir)\n\t\t}\n\t}\n\n\tif packageName == \"\" {\n\t\treturn defaultPackageName, fmt.Errorf(\"no Go package found in %q\", dir)\n\t}\n\treturn packageName, nil\n}\n\n// detectCLIVersion detects the CLI version by:","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L225-L261","documentation":"detectPackageName walks a directory's .go files and parses each package clause with go/parser to find the package name. If any file's package clause cannot be parsed, it wraps the parser error and aborts with this message. It indicates a corrupted, unreadable, or non-Go file inside the directory being bundled.","triggerScenarios":"A .go file in the directory passed to the bundler contains a syntax error in (or before) its package clause, is empty, or cannot be read from disk; parser.ParseFile with PackageClauseOnly then fails and this error is returned.","commonSituations":"Partially written or truncated files from an interrupted VCS checkout; stray files with a .go extension that aren't Go source; permission or encoding issues causing the file to be unreadable.","solutions":["Run gofmt -l or go build on the directory to find and fix the syntactically invalid .go file","Inspect the wrapped path %q in the error and open that exact file to repair its package clause","Remove or rename any non-Go files that use a .go extension","Check file permissions and re-run the bundler"],"exampleFix":"// before: bundler fails on broken file\n// $ bundler ./pkg  -> failed to parse package clause in \"pkg/gen.go\"\n// after: fix the file's package clause\n// -package gen\n// +package generated","handlingStrategy":"validation","validationCode":"fset := token.NewFileSet()\nif _, err := parser.ParseFile(fset, path, nil, parser.PackageClauseOnly); err != nil {\n    return fmt.Errorf(\"invalid Go source %s: %v\", path, err)\n}\n// or simply: gofmt -l ./dir && go vet ./dir before bundling","typeGuard":null,"tryCatchPattern":"if _, err := bundle(dir); err != nil {\n    var parseErr *os.PathError\n    if errors.Is(err, os.ErrPermission) || strings.Contains(err.Error(), \"failed to parse package clause\") {\n        // repair or exclude the offending file, then retry\n    }\n}","preventionTips":["Run gofmt/go build in CI before invoking the bundler","Keep only real Go source files with a .go extension","Verify VCS checkouts complete cleanly"],"tags":["go","parsing","bundling","file"],"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"}