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 ImportPath string
7 Errs []error
8 }
9 10 func (e *MultiError) Error() string {
11 // Return the first error, to conform to the error interface. Clients should
12 // really do a type-assertion on *MultiError.
13 return e.Errs[0].Error()
14 }
15 16 // newMultiError returns a *MultiError if there is more than one error, or
17 // returns that error directly when there is only one. Passing an empty slice
18 // will return nil (because there is no error).
19 // The importPath may be passed if this error is for a single package.
20 func newMultiError(errs []error, importPath string) error {
21 switch len(errs) {
22 case 0:
23 return nil
24 case 1:
25 return errs[0]
26 default:
27 return &MultiError{importPath, errs}
28 }
29 }
30 31 // commandError is an error type to wrap os/exec.Command errors. This provides
32 // some more information regarding what went wrong while running a command.
33 type commandError struct {
34 Msg string
35 File string
36 Err error
37 }
38 39 func (e *commandError) Error() string {
40 return e.Msg + " " + e.File + ": " + e.Err.Error()
41 }
42