-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
99 lines (82 loc) · 2.21 KB
/
errors.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2014 Daniel Theophanes.
// Use of this source code is governed by a zlib-style
// license that can be found in the LICENSE file.
package rdb
import (
"bytes"
"errors"
"fmt"
)
var ErrScanNull = errors.New("can only scan NULL value into a Nullable type")
var ErrPreparedTokenNotValid = errors.New("the prepared token is not valid")
// Should be returned by a driver that doesn't implement a feature.
var ErrNotImplemented = errors.New("the feature has not been implemented")
// Used when a column lookup fails, either with a name or index.
type ErrorColumnNotFound struct {
At string
Name string
Index int
}
func (err ErrorColumnNotFound) Error() string {
if len(err.Name) == 0 {
return fmt.Sprintf("At <%s>, Column index not valid: %d", err.At, err.Index)
}
return fmt.Sprintf("At <%s>, Column name not valid: %s", err.At, err.Name)
}
// List of SQL errors returned by the server.
type Errors []*Message
func (errs Errors) Error() string {
bb := &bytes.Buffer{}
if errs == nil {
return ""
}
for i, err := range errs {
if i != 0 {
bb.WriteString("\n")
}
bb.WriteString(fmt.Sprintf("%v", err))
}
return bb.String()
}
type MessageType byte
const (
_ = iota
SqlError MessageType = iota
SqlInfo
)
func (mt MessageType) String() string {
switch mt {
default:
return "?"
case SqlError:
return "ERROR"
case SqlInfo:
return "INFO"
}
}
// SQL errors reported by the server.
// Must always be wrapped by Errors.
// This is why it doesn't satisfy the error interface.
type Message struct {
Type MessageType
Message string
ServerName string
ProcName string
LineNumber int32
SqlState string
Number int32
State byte
Class byte
}
func (err *Message) String() string {
return fmt.Sprintf("(%s %s: %d) L%d: %s (%d, %d)", err.ServerName, err.ProcName, err.Number, err.LineNumber, err.Message, err.State, err.Class)
}
// Exposed to help isolate error paths when starting a client.
type DriverNotFound struct {
name string
}
func (dr DriverNotFound) Error() string {
return fmt.Sprintf("Driver name not found: %s", dr.name)
}
var ErrArity = errors.New("result row count does not match desired arity")
var ErrCancel = errors.New("Query Cancelled")