{"record":{"id":"f1833224369ea6f0","repo":"dagger/dagger","slug":"package-name-is-empty","errorCode":null,"errorMessage":"package name is empty","messagePattern":"package name is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/codegen/generator/go/loader.go","lineNumber":64,"sourceCode":"\t\t\treturn astFile, nil\n\t\t},\n\t\t// Print some debug logs with timing information to stdout\n\t\tLogf: func(format string, args ...any) {\n\t\t\tfmt.Printf(format+\"\\n\", args...)\n\t\t},\n\t}, \".\")\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\tswitch len(pkgs) {\n\tcase 0:\n\t\treturn nil, nil, fmt.Errorf(\"no packages found in %s\", dir)\n\tcase 1:\n\t\tif pkgs[0].Name == \"\" && !allowEmpty {\n\t\t\t// this can happen when:\n\t\t\t// - loading an empty dir within an existing Go module\n\t\t\t// - loading a dir that is not included in a parent go.work\n\t\t\treturn nil, nil, fmt.Errorf(\"package name is empty\")\n\t\t}\n\t\treturn pkgs[0], fset, nil\n\tdefault:\n\t\t// this would mean I don't understand how loading '.' works\n\t\treturn nil, nil, fmt.Errorf(\"expected 1 package, got %d\", len(pkgs))\n\t}\n}\n","sourceCodeStart":46,"sourceCodeEnd":72,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/cmd/codegen/generator/go/loader.go#L46-L72","documentation":"Exactly one package was loaded, but its Name is empty (an unnamed/synthetic package), and codegen does not allow that for this entry point. Per the source comment this happens when loading an empty dir within an existing Go module, or a dir not included in a parent go.work. Pass allowEmpty to accept it.","triggerScenarios":"loadPackage loads '.' and gets a single package whose packages.Package.Name == \"\" while allowEmpty is false — i.e. the directory has no compilable Go files of its own but sits inside a module, or the directory isn't part of the active go.work.","commonSituations":"`dagger init` in a subdir of a Go module with no Go source files yet; developing a module in a directory missing from go.work; all files in the dir excluded by build tags so the loader produces a nameless package; generating a module in a fresh dir before writing any code.","solutions":["Add a Go source file with a valid `package` clause (e.g. `package main` with `type MyModule struct{}`) to the directory","If the directory is part of a multi-module workspace, add it to go.work (`go work use ./path`)\n\nCheck the package clause of existing files is valid and files aren't excluded by build tags","If this is intentional (client generation into an empty dir), use the code path that sets allowEmpty=true","Run `go list ./...` in the dir to see what the toolchain itself resolves"],"exampleFix":"// before: empty dir inside a module\n// after:\ncat > main.go <<'EOF'\npackage main\n\ntype MyModule struct{}\n\nfunc main() {}\nEOF\ndagger develop","handlingStrategy":"validation","validationCode":"pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedName | packages.NeedTypes}, \".\")\nif err == nil && len(pkgs) == 1 && pkgs[0].Name == \"\" {\n\tlog.Fatal(\"dir is an unnamed package: add a .go file or add the module to go.work\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write main.go with `package main` before initializing a Dagger module in a Go subdir","Keep every module dir listed in go.work (`go work use ./dir`)","Avoid build tags that exclude all files in the module dir","Verify with `go list ./...` that the package resolves with a name"],"tags":["go","loader","packages","workspace"],"backgroundTag":"go-package-name-empty","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}