-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
45 lines (39 loc) · 940 Bytes
/
error.go
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
package sqlcode
import (
"bytes"
"fmt"
mssql "github.com/denisenkom/go-mssqldb"
"github.com/vippsas/sqlcode/sqlparser"
"strings"
)
type SQLUserError struct {
Wrapped mssql.Error
Batch Batch
}
func (s SQLUserError) Error() string {
var buf bytes.Buffer
if _, fmterr := fmt.Fprintf(&buf, "\n"); fmterr != nil {
panic(fmterr)
}
for _, item := range s.Wrapped.All {
if _, fmterr := fmt.Fprintf(&buf, "\n%s:%d (%s): %s",
s.Batch.StartPos.File,
s.Batch.LineNumberInInput(int(item.LineNo)),
item.ProcName,
item.Message); fmterr != nil {
panic(fmterr)
}
}
return buf.String()
}
type SQLCodeParseErrors struct {
Errors []sqlparser.Error
}
func (e SQLCodeParseErrors) Error() string {
var msg strings.Builder
msg.WriteString("sqlcode syntax error:\n\n")
for _, e := range e.Errors {
msg.WriteString(fmt.Sprintf("%s:%d:%d: %s\n", e.Pos.File, e.Pos.Line, e.Pos.Col, e.Message))
}
return msg.String()
}