aboutsummaryrefslogtreecommitdiffhomepage
path: root/diagnostics/diagnostics.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-07-21 14:12:55 +0200
committerRon Evans <[email protected]>2024-07-21 18:23:49 +0200
commit04d1261f8a48b18a4404c52f858c35c0668316cd (patch)
tree850babc5c14ae4fb20f1e9d9ff67dd20958d9688 /diagnostics/diagnostics.go
parent3e2230eadb14d0e54db621976d60d654487f891a (diff)
downloadtinygo-04d1261f8a48b18a4404c52f858c35c0668316cd.tar.gz
tinygo-04d1261f8a48b18a4404c52f858c35c0668316cd.zip
build: add package ID to compiler and optimization error messages
This improves error reporting slightly.
Diffstat (limited to 'diagnostics/diagnostics.go')
-rw-r--r--diagnostics/diagnostics.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/diagnostics/diagnostics.go b/diagnostics/diagnostics.go
index f9261e292..e58becfb8 100644
--- a/diagnostics/diagnostics.go
+++ b/diagnostics/diagnostics.go
@@ -43,17 +43,10 @@ func CreateDiagnostics(err error) ProgramDiagnostic {
if err == nil {
return nil
}
- switch err := err.(type) {
- case *builder.MultiError:
- var diags ProgramDiagnostic
- for _, err := range err.Errs {
- diags = append(diags, createPackageDiagnostic(err))
- }
- return diags
- default:
- return ProgramDiagnostic{
- createPackageDiagnostic(err),
- }
+ // Right now, the compiler will only show errors for the first pacakge that
+ // fails to build. This is likely to change in the future.
+ return ProgramDiagnostic{
+ createPackageDiagnostic(err),
}
}
@@ -63,6 +56,14 @@ func createPackageDiagnostic(err error) PackageDiagnostic {
// Extract diagnostics for this package.
var pkgDiag PackageDiagnostic
switch err := err.(type) {
+ case *builder.MultiError:
+ if err.ImportPath != "" {
+ pkgDiag.ImportPath = err.ImportPath
+ }
+ for _, err := range err.Errs {
+ diags := createDiagnostics(err)
+ pkgDiag.Diagnostics = append(pkgDiag.Diagnostics, diags...)
+ }
case loader.Errors:
if err.Pkg != nil {
pkgDiag.ImportPath = err.Pkg.ImportPath