@@ -156,6 +156,10 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
156
156
}
157
157
}
158
158
159
+ if err != nil {
160
+ return fmt .Errorf ("packages.Load error: %w" , err )
161
+ }
162
+
159
163
if standalone {
160
164
// Handle standalone package result.
161
165
//
@@ -173,20 +177,29 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
173
177
if s .view .typ == GoPackagesDriverView {
174
178
errorf = fmt .Errorf // all bets are off
175
179
}
180
+ for _ , pkg := range pkgs {
181
+ // Don't report bugs if any packages have errors.
182
+ // For example: given go list errors, go/packages may synthesize a
183
+ // package with ID equal to the query.
184
+ if len (pkg .Errors ) > 0 {
185
+ errorf = fmt .Errorf
186
+ break
187
+ }
188
+ }
176
189
177
190
var standalonePkg * packages.Package
178
191
for _ , pkg := range pkgs {
179
192
if pkg .ID == "command-line-arguments" {
180
193
if standalonePkg != nil {
181
- return errorf ("internal error: go/packages returned multiple standalone packages" )
194
+ return errorf ("go/packages returned multiple standalone packages" )
182
195
}
183
196
standalonePkg = pkg
184
197
} else if packagesinternal .GetForTest (pkg ) == "" && ! strings .HasSuffix (pkg .ID , ".test" ) {
185
- return errorf ("internal error: go/packages returned unexpected package %q for standalone file" , pkg .ID )
198
+ return errorf ("go/packages returned unexpected package %q for standalone file" , pkg .ID )
186
199
}
187
200
}
188
201
if standalonePkg == nil {
189
- return errorf ("internal error: go/packages failed to return non-test standalone package" )
202
+ return errorf ("go/packages failed to return non-test standalone package" )
190
203
}
191
204
if len (standalonePkg .CompiledGoFiles ) > 0 {
192
205
pkgs = []* packages.Package {standalonePkg }
@@ -196,10 +209,7 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
196
209
}
197
210
198
211
if len (pkgs ) == 0 {
199
- if err == nil {
200
- err = errNoPackages
201
- }
202
- return fmt .Errorf ("packages.Load error: %w" , err )
212
+ return fmt .Errorf ("packages.Load error: %w" , errNoPackages )
203
213
}
204
214
205
215
moduleErrs := make (map [string ][]packages.Error ) // module path -> errors
0 commit comments