{"record":{"id":"58de8398fd91ed57","repo":"golang/go","slug":"no-files-in-package-s","errorCode":null,"errorMessage":"no files in package %s","messagePattern":"no files in package (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/export/main.go","lineNumber":125,"sourceCode":"\t}\n\tif err := gcexportdata.Write(f, fset, pkg); err != nil {\n\t\tf.Close() // ignore error\n\t\treturn err\n\t}\n\treturn f.Close()\n}\n\nfunc readConfig(filename string) (*config, error) {\n\tdata, err := os.ReadFile(filename)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcfg := new(config)\n\tif err := json.Unmarshal(data, cfg); err != nil {\n\t\treturn nil, fmt.Errorf(\"can't decode input %s: %v\", filename, err)\n\t}\n\tif len(cfg.GoFiles) == 0 {\n\t\treturn nil, fmt.Errorf(\"no files in package %s\", cfg.ImportPath)\n\t}\n\treturn cfg, nil\n}\n\nfunc makeTypesImporter(cfg *config, fset *token.FileSet) types.Importer {\n\timports := make(map[string]*types.Package)\n\timports[\"unsafe\"] = types.Unsafe\n\treturn importerFunc(func(importPath string) (*types.Package, error) {\n\t\tpkgPath, ok := cfg.ImportMap[importPath]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"can't resolve import %s\", importPath)\n\t\t}\n\t\t// Check for cache hit.\n\t\tif pkg, ok := imports[pkgPath]; ok && pkg.Complete() {\n\t\t\treturn pkg, nil\n\t\t}\n\t\t// Miss.\n\t\tcfgPath, ok := cfg.PackageFile[pkgPath]","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/export/main.go#L107-L143","documentation":"Thrown by `go tool export` (an internal helper driven by `go list -export`) inside readConfig, right after JSON-decoding the unit.cfg file. The config struct's GoFiles slice is empty, meaning the package has no Go source files to parse and type-check, so the exporter refuses to proceed and names cfg.ImportPath. The export tool is not intended to be invoked by end users; `go list -export` generates its config.","triggerScenarios":"A unit.cfg with a GoFiles array of length zero is passed to `go tool export`. This occurs when the package being exported contains no .go files for the active build context (e.g. an assembly-only package, or all .go files excluded by build tags), or when a hand-written config omits GoFiles.","commonSituations":"Running `go tool export unit.cfg` directly on a hand-authored config; building a package composed solely of .s assembly or cgo .c/.h files with no .go files; GOOS/GOARCH build constraints filtering out every Go file; a stale or corrupted config produced by an interrupted `go list -export`.","solutions":["Do not call `go tool export` directly; run `go list -export <pkg>` which generates a correct config including GoFiles.","If you must supply a config, ensure cfg.GoFiles contains at least one absolute path to a .go file that belongs to the package.","Confirm the package actually has Go source files for your GOOS/GOARCH (run `go list -f '{{.GoFiles}}' <pkg>`).","Re-run `go list -export` after any source/build-context change to regenerate the config."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before passing a config to export, verify it has source files.\nif len(cfg.GoFiles) == 0 {\n    return fmt.Errorf(\"config for %s has no Go files; regenerate via 'go list -export'\", cfg.ImportPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `go list -export <pkg>` over invoking `go tool export` directly.","Treat unit.cfg files as generated artifacts; regenerate after source or build-context changes.","Confirm packages have Go source for the target GOOS/GOARCH before exporting."],"tags":["go-toolchain","export","config","go-list","build-constraints"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}