From d7773d3e86e82a64c79a04fa70f740daf333a3be Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 9 Jul 2024 18:08:51 +0200 Subject: 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. --- main.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index e18f12f1f..66a172133 100644 --- a/main.go +++ b/main.go @@ -1340,15 +1340,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 { -- cgit v1.2.3