forked from pingcap/tidb
/
errors.go
55 lines (48 loc) · 2.01 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
// Copyright 2016 PingCAP, Inc.
//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/terror"
)
var (
// ErrDataTooLong is returned when converts a string value that is longer than field type length.
ErrDataTooLong = terror.ClassTypes.New(codeDataTooLong, "Data Too Long")
// ErrTruncated is returned when data has been truncated during conversion.
ErrTruncated = terror.ClassTypes.New(codeTruncated, "Data Truncated")
// ErrOverflow is returned when data is out of range for a field type.
ErrOverflow = terror.ClassTypes.New(codeOverflow, msgOverflow)
// ErrDivByZero is return when do division by 0.
ErrDivByZero = terror.ClassTypes.New(codeDivByZero, "Division by 0")
// ErrBadNumber is return when parsing an invalid binary decimal number.
ErrBadNumber = terror.ClassTypes.New(codeBadNumber, "Bad Number")
)
const (
codeBadNumber terror.ErrCode = 1
codeDataTooLong terror.ErrCode = terror.ErrCode(mysql.ErrDataTooLong)
codeTruncated terror.ErrCode = terror.ErrCode(mysql.WarnDataTruncated)
codeOverflow terror.ErrCode = terror.ErrCode(mysql.ErrDataOutOfRange)
codeDivByZero terror.ErrCode = terror.ErrCode(mysql.ErrDivisionByZero)
)
var (
msgOverflow = mysql.MySQLErrName[mysql.ErrDataOutOfRange]
)
func init() {
typesMySQLErrCodes := map[terror.ErrCode]uint16{
codeDataTooLong: mysql.ErrDataTooLong,
codeTruncated: mysql.WarnDataTruncated,
codeOverflow: mysql.ErrDataOutOfRange,
codeDivByZero: mysql.ErrDivisionByZero,
}
terror.ErrClassToMySQLCodes[terror.ClassTypes] = typesMySQLErrCodes
}