forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
103 lines (81 loc) · 1.79 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
100
101
102
103
package gorethink
import (
"bytes"
"errors"
"fmt"
p "github.com/dancannon/gorethink/ql2"
)
func printCarrots(t Term, frames []*p.Frame) string {
var frame *p.Frame
if len(frames) > 1 {
frame, frames = frames[0], frames[1:]
} else if len(frames) == 1 {
frame, frames = frames[0], []*p.Frame{}
}
for i, arg := range t.args {
if frame.GetPos() == int64(i) {
t.args[i] = Term{
termType: p.Term_DATUM,
data: printCarrots(arg, frames),
}
}
}
for k, arg := range t.optArgs {
if frame.GetOpt() == k {
t.optArgs[k] = Term{
termType: p.Term_DATUM,
data: printCarrots(arg, frames),
}
}
}
b := &bytes.Buffer{}
for _, c := range t.String() {
if c != '^' {
b.WriteString(" ")
} else {
b.WriteString("^")
}
}
return b.String()
}
// Error constants
var ErrEmptyResult = errors.New("The result does not contain any more rows")
// Connection/Response errors
type rqlResponseError struct {
response *p.Response
term Term
}
func (e rqlResponseError) Error() string {
message, _ := deconstructDatum(e.response.GetResponse()[0], map[string]interface{}{})
return fmt.Sprintf("gorethink: %s in: \n%s", message, e.term)
}
func (e rqlResponseError) String() string {
return e.Error()
}
type RqlCompileError struct {
rqlResponseError
}
type RqlRuntimeError struct {
rqlResponseError
}
type RqlClientError struct {
rqlResponseError
}
type RqlDriverError struct {
message string
}
func (e RqlDriverError) Error() string {
return fmt.Sprintf("gorethink: %s", e.message)
}
func (e RqlDriverError) String() string {
return e.Error()
}
type RqlConnectionError struct {
message string
}
func (e RqlConnectionError) Error() string {
return fmt.Sprintf("gorethink: %s", e.message)
}
func (e RqlConnectionError) String() string {
return e.Error()
}