Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
53 lines
929 B
Go
53 lines
929 B
Go
package multierr
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sqlc-dev/sqlc/internal/source"
|
|
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
|
|
)
|
|
|
|
type FileError struct {
|
|
Filename string
|
|
Line int
|
|
Column int
|
|
Err error
|
|
}
|
|
|
|
func (e *FileError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type Error struct {
|
|
errs []*FileError
|
|
}
|
|
|
|
func (e *Error) Add(filename, in string, loc int, err error) {
|
|
line := 1
|
|
column := 1
|
|
if lerr, ok := err.(*sqlerr.Error); ok {
|
|
if lerr.Location != 0 {
|
|
loc = lerr.Location
|
|
} else if lerr.Line != 0 && lerr.Column != 0 {
|
|
line = lerr.Line
|
|
column = lerr.Column
|
|
}
|
|
}
|
|
if in != "" && loc != 0 {
|
|
line, column = source.LineNumber(in, loc)
|
|
}
|
|
e.errs = append(e.errs, &FileError{filename, line, column, err})
|
|
}
|
|
|
|
func (e *Error) Errs() []*FileError {
|
|
return e.errs
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
return fmt.Sprintf("multiple errors: %d errors", len(e.errs))
|
|
}
|
|
|
|
func New() *Error {
|
|
return &Error{}
|
|
}
|