loader: handle go list errors inside TinyGo

Instead of exiting with an error, handle these errors internally.
This will enable a few improvements in the future.
This commit is contained in:
Ayke van Laethem
2024-07-09 18:08:51 +02:00
parent 3de78fcdc6
commit a6602dc708
9 changed files with 95 additions and 9 deletions
+21 -5
View File
@@ -1335,15 +1335,31 @@ func printCompilerError(err error, logln func(...interface{}), wd string) {
}
}
case loader.Errors:
logln("#", err.Pkg.ImportPath)
// Parser errors, typechecking errors, or `go list` errors.
// err.Pkg is nil for `go list` errors.
if err.Pkg != nil {
logln("#", err.Pkg.ImportPath)
}
for _, err := range err.Errs {
printCompilerError(err, logln, wd)
}
case loader.Error:
logln(err.Err.Error())
logln("package", err.ImportStack[0])
for _, pkgPath := range err.ImportStack[1:] {
logln("\timports", pkgPath)
if err.Err.Pos.Filename != "" {
// Probably a syntax error in a dependency.
printCompilerError(err.Err, logln, wd)
} else {
// Probably an "import cycle not allowed" error.
logln("package", err.ImportStack[0])
for i := 1; i < len(err.ImportStack); i++ {
pkgPath := err.ImportStack[i]
if i == len(err.ImportStack)-1 {
// last package
logln("\timports", pkgPath+": "+err.Err.Error())
} else {
// not the last pacakge
logln("\timports", pkgPath)
}
}
}
case *builder.MultiError:
for _, err := range err.Errs {