(opts *GeneratorOptions)
| 128 | } |
| 129 | |
| 130 | func runPackageMode(opts *GeneratorOptions) error { |
| 131 | // Legacy package-based mode |
| 132 | cfg := &packages.Config{ |
| 133 | Mode: packages.NeedTypes | packages.NeedSyntax | packages.NeedName | packages.NeedFiles | packages.NeedTypesInfo, |
| 134 | } |
| 135 | |
| 136 | pkgs, err := packages.Load(cfg, opts.PackageDir) |
| 137 | if err != nil { |
| 138 | return fmt.Errorf("loading packages: %w", err) |
| 139 | } |
| 140 | |
| 141 | if len(pkgs) == 0 { |
| 142 | return fmt.Errorf("no packages found") |
| 143 | } |
| 144 | |
| 145 | if packages.PrintErrors(pkgs) > 0 { |
| 146 | // Check if any errors are compile-time guard related |
| 147 | var allErrors []string |
| 148 | for _, pkg := range pkgs { |
| 149 | for _, err := range pkg.Errors { |
| 150 | allErrors = append(allErrors, err.Error()) |
| 151 | } |
| 152 | } |
| 153 | errorMsg := strings.Join(allErrors, "; ") |
| 154 | |
| 155 | // If this looks like a compile-time guard error, provide better context |
| 156 | if isCompileGuardError(errorMsg) { |
| 157 | return fmt.Errorf("compile-time guard detected struct changes: %s", errorMsg) |
| 158 | } |
| 159 | |
| 160 | return fmt.Errorf("errors in packages") |
| 161 | } |
| 162 | |
| 163 | // Process each package (legacy behavior) |
| 164 | for _, pkg := range pkgs { |
| 165 | if err := processPackage(pkg, opts.TypeList); err != nil { |
| 166 | return fmt.Errorf("processing package %s: %w", pkg.PkgPath, err) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | func processPackageFile(pkg *packages.Package, sourceFile string, typeList string) error { |
| 174 | // Convert to absolute path for comparison |
no test coverage detected