-
Notifications
You must be signed in to change notification settings - Fork 34
/
error.go
99 lines (86 loc) · 3.09 KB
/
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
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 2020 the go-etl Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package element
import (
"errors"
"fmt"
)
// 错误
var (
ErrColumnExist = errors.New("column exist") //列存在错误
ErrColumnNotExist = errors.New("column does not exist") //列不存在错误
ErrNilValue = errors.New("column value is nil") //空值错误
ErrIndexOutOfRange = errors.New("column index is out of range") //索引值超出范围
ErrValueNotInt64 = errors.New("value is not int64") //不是int64错误
ErrValueInfinity = errors.New("value is infinity") //无穷大实数错误
ErrNotColumnValueClonable = errors.New("columnValue is not clonable") //不是可克隆列值
ErrNotColumnValueComparable = errors.New("columnValue is not comparable") //不是可比较列值
ErrColumnNameNotEqual = errors.New("column name is not equal") //列名不同
)
// TransformError 转化错误
type TransformError struct {
err error
msg string
}
// NewTransformError 根据消息msg和错误err生成转化错误
func NewTransformError(msg string, err error) *TransformError {
for uerr := err; uerr != nil; uerr = errors.Unwrap(err) {
err = uerr
}
return &TransformError{
msg: msg,
err: err,
}
}
// NewTransformErrorFormColumnTypes 从one类型到other类型转化错误err生成转化错误
func NewTransformErrorFormColumnTypes(one, other ColumnType, err error) *TransformError {
return NewTransformError(fmt.Sprintf("%s transform to %s", one, other), err)
}
// NewTransformErrorFormString 从one到other转化错误err生成转化错误
func NewTransformErrorFormString(one, other string, err error) *TransformError {
return NewTransformError(fmt.Sprintf("%s transform to %s", one, other), err)
}
func (e *TransformError) Error() string {
if e.err != nil {
return fmt.Sprintf("%s error: %v", e.msg, e.err)
}
return fmt.Sprintf("%s", e.msg)
}
func (e *TransformError) Unwrap() error {
return e.err
}
// SetError 设置错误
type SetError struct {
err error
msg string
}
// NewSetError 通过值i设置成累心other类型的错误err生成设置错误
func NewSetError(i interface{}, other ColumnType, err error) *SetError {
for uerr := err; uerr != nil; uerr = errors.Unwrap(err) {
err = uerr
}
return &SetError{
msg: fmt.Sprintf("%T set to %s", i, other),
err: err,
}
}
func (e *SetError) Error() string {
if e.err != nil {
return fmt.Sprintf("%s error: %v", e.msg, e.err)
}
return fmt.Sprintf("%s", e.msg)
}
func (e *SetError) Unwrap() error {
return e.err
}