{"record":{"id":"53548cc7b98e9bbb","repo":"ent/ent","slug":"load-package-info-w","errorCode":null,"errorMessage":"load package info: %w","messagePattern":"load package info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/internal/base/packages.go","lineNumber":41,"sourceCode":"func PkgPath(config *packages.Config, target string) (string, error) {\n\tif config == nil {\n\t\tconfig = DefaultConfig\n\t}\n\tpathCheck, err := filepath.Abs(target)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tvar parts []string\n\tif _, err := os.Stat(pathCheck); os.IsNotExist(err) {\n\t\tparts = append(parts, filepath.Base(pathCheck))\n\t\tpathCheck = filepath.Dir(pathCheck)\n\t}\n\t// Try maximum 2 directories above the given\n\t// target to find the root package or module.\n\tfor i := 0; i < 2; i++ {\n\t\tpkgs, err := packages.Load(config, pathCheck)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"load package info: %w\", err)\n\t\t}\n\t\tif len(pkgs) == 0 || len(pkgs[0].Errors) != 0 {\n\t\t\tparts = append(parts, filepath.Base(pathCheck))\n\t\t\tpathCheck = filepath.Dir(pathCheck)\n\t\t\tcontinue\n\t\t}\n\t\tpkgPath := pkgs[0].PkgPath\n\t\tfor j := len(parts) - 1; j >= 0; j-- {\n\t\t\tpkgPath = path.Join(pkgPath, parts[j])\n\t\t}\n\t\treturn pkgPath, nil\n\t}\n\treturn \"\", fmt.Errorf(\"root package or module was not found for: %s\", target)\n}\n","sourceCodeStart":23,"sourceCodeEnd":56,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/cmd/internal/base/packages.go#L23-L56","documentation":"PkgPath uses golang.org/x/tools/go/packages.Load to resolve an import path for a target directory by loading the package there (searching up to 2 parent dirs). This error wraps a hard failure of packages.Load itself (driver invocation failed), as opposed to package-level compile errors which are handled separately. It means the go/packages driver could not run at all.","triggerScenarios":"Calling base.PkgPath (used by entc to compute import paths) in an environment where `go list` fails outright: no go.mod/GOPATH setup, corrupted module cache, missing Go toolchain on PATH, or GOFLAGS/module errors that crash the loader.","commonSituations":"Running ent codegen outside a Go module; GO111MODULE mismatch; broken GOPATH or GOFLAGS; a go directive version newer than the installed toolchain; running in a sandbox without the go binary.","solutions":["Run `go version` and `go list ./...` in the target dir to reproduce the underlying loader failure and fix it (install/upgrade Go).","Ensure the command runs inside a valid module (go.mod exists) or set GO111MODULE appropriately.","Clear a corrupt module/build cache if `go list` reports cache corruption (go clean -modcache).","Fix GOFLAGS/GOENV if custom flags break `go list`; run `go env` to inspect."],"exampleFix":"// before\n$ entc generate  // outside any module -> go/packages driver fails\n// after\n$ cd myapp && go mod init example.com/myapp && go get entgo.io/ent && go run entc.go","handlingStrategy":"validation","validationCode":"cmd := exec.Command(\"go\", \"list\", \"./...\")\ncmd.Dir = targetDir\nif out, err := cmd.CombinedOutput(); err != nil {\n    return fmt.Errorf(\"go list failed, go/packages will too: %v: %s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"pkgPath, err := base.PkgPath(pwd)\nif err != nil {\n    if strings.Contains(err.Error(), \"load package info\") {\n        log.Fatalf(\"go/packages driver failed; check Go toolchain/module setup: %v\", err)\n    }\n    return err\n}","preventionTips":["Always run ent codegen inside a valid Go module","Pin and verify the Go toolchain version on PATH in CI","Avoid exotic GOFLAGS that break `go list`","Run `go env` sanity checks before codegen steps"],"tags":["go","toolchain","packages","ent","module-resolution"],"backgroundTag":"go-package-load-failed","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}