loader: improve error messages for failed imports

Add location information (whenever possible) to failed imports. This
helps in debugging where an incorrect import came from.

For example, show the following error message:

    /home/ayke/src/github.com/tinygo-org/tinygo/src/machine/machine.go:5:8: cannot find package "foobar" in any of:
        /usr/local/go/src/foobar (from $GOROOT)
        /home/ayke/src/foobar (from $GOPATH)

Instead of the following:

    error: cannot find package "foobar" in any of:
        /usr/local/go/src/foobar (from $GOROOT)
        /home/ayke/src/foobar (from $GOPATH)
This commit is contained in:
Ayke van Laethem
2019-12-31 17:44:34 +01:00
committed by Ron Evans
parent b424056721
commit 69c1d802e1
2 changed files with 20 additions and 5 deletions
+6 -2
View File
@@ -251,13 +251,17 @@ func (c *Compiler) Compile(mainPath string) []error {
return []error{err}
}
} else {
_, err = lprogram.Import(mainPath, wd)
_, err = lprogram.Import(mainPath, wd, token.Position{
Filename: "build command-line-arguments",
})
if err != nil {
return []error{err}
}
}
_, err = lprogram.Import("runtime", "")
_, err = lprogram.Import("runtime", "", token.Position{
Filename: "build default import",
})
if err != nil {
return []error{err}
}