From 9583439be46fed7e5a782b384f65bb27788ba487 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 12 Oct 2024 10:54:22 +0200 Subject: [PATCH] loader: make sure we always return an error even without type errors This issue was originally reported here: https://github.com/NixOS/nixpkgs/pull/341170#issuecomment-2359237471 The fix here isn't a great fix, it turns the error message from this: # runtime/interrupt into this: # runtime/interrupt package requires newer Go version go1.23 ...so not great, because it doesn't show the real error message (which is that TinyGo wasn't compiled with the right Go version). But at least it gives a hint in the right direction. It's difficult to test for this specific case, so I've left out testing in this case (boo!) --- loader/loader.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/loader/loader.go b/loader/loader.go index 6786ee533..f3ffa8614 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -432,7 +432,15 @@ func (p *Package) Check() error { if err, ok := err.(Errors); ok { return err } - return Errors{p, typeErrors} + if len(typeErrors) != 0 { + // Got type errors, so return them. + return Errors{p, typeErrors} + } + // This can happen in some weird cases. + // The only case I know is when compiling a Go 1.23 program, with a + // TinyGo version that supports Go 1.23 but is compiled using Go 1.22. + // So this should be pretty rare. + return Errors{p, []error{err}} } p.Pkg = typesPkg