diff options
author | Ayke van Laethem <[email protected]> | 2024-07-09 18:08:51 +0200 |
---|---|---|
committer | Ayke <[email protected]> | 2024-07-13 13:26:26 +0200 |
commit | d7773d3e86e82a64c79a04fa70f740daf333a3be (patch) | |
tree | 99361d45c7872f8da2d2c2e6fea55090942a9570 /main.go | |
parent | b04b690842f837aedc6d8187bb4a4200b0cc6acc (diff) | |
download | tinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.tar.gz tinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.zip |
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.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -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 { |