Check errors on loading package (#130)
This commit is contained in:
parent
c5b1da6fe9
commit
70fed06ee3
@ -222,6 +222,12 @@ func pkgInfoFromPath(srcDir string, mode packages.LoadMode) (*packages.Package,
|
|||||||
if len(pkgs) > 1 {
|
if len(pkgs) > 1 {
|
||||||
return nil, errors.New("More than one package was found")
|
return nil, errors.New("More than one package was found")
|
||||||
}
|
}
|
||||||
|
if errs := pkgs[0].Errors; len(errs) != 0 {
|
||||||
|
if len(errs) == 1 {
|
||||||
|
return nil, errs[0]
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("%s (and %d more errors)", errs[0], len(errs)-1)
|
||||||
|
}
|
||||||
return pkgs[0], nil
|
return pkgs[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,6 +544,17 @@ func TestImportedPackageWithSameName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseError(t *testing.T) {
|
||||||
|
_, err := New(Config{SrcDir: "testpackages/_parseerror/service"})
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("expected error but got nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), `could not import github.com/matryer/notexist (invalid package name: "")`) {
|
||||||
|
t.Errorf("unexpected error: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// normalize normalizes \r\n (windows) and \r (mac)
|
// normalize normalizes \r\n (windows) and \r (mac)
|
||||||
// into \n (unix)
|
// into \n (unix)
|
||||||
func normalize(d []byte) []byte {
|
func normalize(d []byte) []byte {
|
||||||
|
8
pkg/moq/testpackages/_parseerror/service/service.go
Normal file
8
pkg/moq/testpackages/_parseerror/service/service.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import "github.com/matryer/notexist"
|
||||||
|
|
||||||
|
// Service does something good with computers.
|
||||||
|
type Service interface {
|
||||||
|
DoSomething(notexist.SomeType) error
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user