forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
52 lines (43 loc) · 933 Bytes
/
error.go
File metadata and controls
52 lines (43 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package multierr
import (
"fmt"
"github.com/kyleconroy/sqlc/internal/source"
"github.com/kyleconroy/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{}
}