@@ -128,7 +128,7 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
128128 }
129129
130130 // List the dependencies of this package, in raw JSON format.
131- extraArgs := []string {"-json" , "-deps" }
131+ extraArgs := []string {"-json" , "-deps" , "-e" }
132132 if config .TestConfig .CompileTestBinary {
133133 extraArgs = append (extraArgs , "-test" )
134134 }
@@ -149,6 +149,7 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
149149
150150 // Parse the returned json from `go list`.
151151 decoder := json .NewDecoder (buf )
152+ var pkgErrors []error
152153 for {
153154 pkg := & Package {
154155 program : p ,
@@ -188,17 +189,24 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
188189 pos .Filename = strings .Join (fields [:len (fields )- 1 ], ":" )
189190 pos .Line , _ = strconv .Atoi (fields [len (fields )- 1 ])
190191 }
192+ if abs , err := filepath .Abs (pos .Filename ); err == nil {
193+ // Make the path absolute, so that error messages will be
194+ // prettier (it will be turned back into a relative path
195+ // when printing the error).
196+ pos .Filename = abs
197+ }
191198 pos .Filename = p .getOriginalPath (pos .Filename )
192199 }
193200 err := scanner.Error {
194201 Pos : pos ,
195202 Msg : pkg .Error .Err ,
196203 }
197204 if len (pkg .Error .ImportStack ) != 0 {
198- return nil , Error {
205+ pkgErrors = append ( pkgErrors , Error {
199206 ImportStack : pkg .Error .ImportStack ,
200207 Err : err ,
201- }
208+ })
209+ continue
202210 }
203211 return nil , err
204212 }
@@ -241,6 +249,13 @@ func Load(config *compileopts.Config, inputPkg string, typeChecker types.Config)
241249 p .Packages [pkg .ImportPath ] = pkg
242250 }
243251
252+ if len (pkgErrors ) != 0 {
253+ // TODO: use errors.Join in Go 1.20.
254+ return nil , Errors {
255+ Errs : pkgErrors ,
256+ }
257+ }
258+
244259 if config .TestConfig .CompileTestBinary && ! strings .HasSuffix (p .sorted [len (p .sorted )- 1 ].ImportPath , ".test" ) {
245260 // Trying to compile a test binary but there are no test files in this
246261 // package.
0 commit comments