github.com/aykevl/tinygo@v0.5.0/loader/errors.go (about) 1 package loader 2 3 import ( 4 "go/token" 5 "strings" 6 ) 7 8 // Errors contains a list of parser errors or a list of typechecker errors for 9 // the given package. 10 type Errors struct { 11 Pkg *Package 12 Errs []error 13 } 14 15 func (e Errors) Error() string { 16 return "could not compile: " + e.Errs[0].Error() 17 } 18 19 // ImportCycleErrors is returned when encountering an import cycle. The list of 20 // packages is a list from the root package to the leaf package that imports one 21 // of the packages in the list. 22 type ImportCycleError struct { 23 Packages []string 24 ImportPositions []token.Position 25 } 26 27 func (e *ImportCycleError) Error() string { 28 var msg strings.Builder 29 msg.WriteString("import cycle:\n\t") 30 msg.WriteString(strings.Join(e.Packages, "\n\t")) 31 msg.WriteString("\n at ") 32 for i, pos := range e.ImportPositions { 33 if i > 0 { 34 msg.WriteString(", ") 35 } 36 msg.WriteString(pos.String()) 37 } 38 return msg.String() 39 }