github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/builder/error.go (about) 1 package builder 2 3 // MultiError is a list of multiple errors (actually: diagnostics) returned 4 // during LLVM IR generation. 5 type MultiError struct { 6 Errs []error 7 } 8 9 func (e *MultiError) Error() string { 10 // Return the first error, to conform to the error interface. Clients should 11 // really do a type-assertion on *MultiError. 12 return e.Errs[0].Error() 13 } 14 15 // newMultiError returns a *MultiError if there is more than one error, or 16 // returns that error directly when there is only one. Passing an empty slice 17 // will lead to a panic. 18 func newMultiError(errs []error) error { 19 switch len(errs) { 20 case 0: 21 panic("attempted to create empty MultiError") 22 case 1: 23 return errs[0] 24 default: 25 return &MultiError{errs} 26 } 27 } 28 29 // commandError is an error type to wrap os/exec.Command errors. This provides 30 // some more information regarding what went wrong while running a command. 31 type commandError struct { 32 Msg string 33 File string 34 Err error 35 } 36 37 func (e *commandError) Error() string { 38 return e.Msg + " " + e.File + ": " + e.Err.Error() 39 }