avoid panic when a package's imports cannot be loaded
I mistakenly understood that, when the DepsErrors field has errors, the Error field would contain an error as well. That is not always the case; for example, the imports_missing package in the added test script had DepsErrors set but Error empty, causing a nil dereference panic. Make the code more robust, and report both kinds of load errors. Fixes #694.pull/703/head
parent
cf49f7f3b1
commit
30927da637
@ -0,0 +1,30 @@
|
||||
! garble build ./...
|
||||
cmpenv stderr stderr.golden
|
||||
|
||||
-- stderr.golden --
|
||||
# test/main/broken
|
||||
broken${/}broken.go:5:16: cannot use 123 (untyped int constant) as string value in variable declaration
|
||||
# test/main/imports_missing
|
||||
package test/main/missing is not in GOROOT (${GOROOT}${/}src${/}test${/}main${/}missing)
|
||||
-- go.mod --
|
||||
module test/main
|
||||
|
||||
go 1.20
|
||||
-- broken/broken.go --
|
||||
package broken
|
||||
|
||||
// A broken package will list in JSON form like:
|
||||
// {..., "Incomplete": true, "Error": {...}, ...}
|
||||
var x string = 123
|
||||
-- imports_broken/imports.go --
|
||||
package imports_broken
|
||||
|
||||
// Importing a broken package will list in JSON form like:
|
||||
// {..., "Incomplete": false, ...}
|
||||
import _ "test/main/broken"
|
||||
-- imports_missing/imports.go --
|
||||
package imports_missing
|
||||
|
||||
// Importing a missing package will list in JSON form like:
|
||||
// {..., "Incomplete": true, "DepsErrors": [...], ...}
|
||||
import _ "test/main/missing"
|
Loading…
Reference in New Issue