aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/exception.go
blob: ccda6f076c0f5984d61a0d6456d91685ade07029 (plain) (blame)
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
package proto

import "github.com/go-faster/errors"

// Exception is server-side error.
type Exception struct {
	Code    Error
	Name    string
	Message string
	Stack   string
	Nested  bool
}

// DecodeAware decodes exception.
func (e *Exception) DecodeAware(r *Reader, _ int) error {
	code, err := r.Int32()
	if err != nil {
		return errors.Wrap(err, "code")
	}
	e.Code = Error(code)

	{
		s, err := r.Str()
		if err != nil {
			return errors.Wrap(err, "name")
		}
		e.Name = s
	}
	{
		s, err := r.Str()
		if err != nil {
			return errors.Wrap(err, "message")
		}
		e.Message = s
	}
	{
		s, err := r.Str()
		if err != nil {
			return errors.Wrap(err, "stack trace")
		}
		e.Stack = s
	}
	nested, err := r.Bool()
	if err != nil {
		return errors.Wrap(err, "nested")
	}
	e.Nested = nested

	return nil
}

// EncodeAware encodes exception.
func (e *Exception) EncodeAware(b *Buffer, _ int) {
	b.PutInt32(int32(e.Code))
	b.PutString(e.Name)
	b.PutString(e.Message)
	b.PutString(e.Stack)
	b.PutBool(e.Nested)
}