Skip to content

Commit 20905c0

Browse files
zhexuanycoocood
authored andcommitted
util/types: cleanup error.Trace (#3113)
1 parent e4608cb commit 20905c0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

util/types/overflow.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
// AddUint64 adds uint64 a and b if no overflow, else returns error.
2424
func AddUint64(a uint64, b uint64) (uint64, error) {
2525
if math.MaxUint64-a < b {
26-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
26+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
2727
}
2828
return a + b, nil
2929
}
@@ -32,7 +32,7 @@ func AddUint64(a uint64, b uint64) (uint64, error) {
3232
func AddInt64(a int64, b int64) (int64, error) {
3333
if (a > 0 && b > 0 && math.MaxInt64-a < b) ||
3434
(a < 0 && b < 0 && math.MinInt64-a > b) {
35-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
35+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
3636
}
3737

3838
return a + b, nil
@@ -45,15 +45,15 @@ func AddInteger(a uint64, b int64) (uint64, error) {
4545
}
4646

4747
if uint64(-b) > a {
48-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
48+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
4949
}
5050
return a - uint64(-b), nil
5151
}
5252

5353
// SubUint64 subtracts uint64 a with b and returns uint64 if no overflow error.
5454
func SubUint64(a uint64, b uint64) (uint64, error) {
5555
if a < b {
56-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
56+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
5757
}
5858
return a - b, nil
5959
}
@@ -63,7 +63,7 @@ func SubInt64(a int64, b int64) (int64, error) {
6363
if (a > 0 && b < 0 && math.MaxInt64-a < -b) ||
6464
(a < 0 && b > 0 && math.MinInt64-a > -b) ||
6565
(a == 0 && b == math.MinInt64) {
66-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
66+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
6767
}
6868
return a - b, nil
6969
}
@@ -79,15 +79,15 @@ func SubUintWithInt(a uint64, b int64) (uint64, error) {
7979
// SubIntWithUint subtracts int64 a with uint64 b and returns uint64 if no overflow error.
8080
func SubIntWithUint(a int64, b uint64) (uint64, error) {
8181
if a < 0 || uint64(a) < b {
82-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
82+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
8383
}
8484
return uint64(a) - b, nil
8585
}
8686

8787
// MulUint64 multiplies uint64 a and b and returns uint64 if no overflow error.
8888
func MulUint64(a uint64, b uint64) (uint64, error) {
8989
if b > 0 && a > math.MaxUint64/b {
90-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
90+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
9191
}
9292
return a * b, nil
9393
}
@@ -123,15 +123,15 @@ func MulInt64(a int64, b int64) (int64, error) {
123123
if negative {
124124
// negative result
125125
if res > math.MaxInt64+1 {
126-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
126+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
127127
}
128128

129129
return -int64(res), nil
130130
}
131131

132132
// positive result
133133
if res > math.MaxInt64 {
134-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
134+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
135135
}
136136

137137
return int64(res), nil
@@ -144,7 +144,7 @@ func MulInteger(a uint64, b int64) (uint64, error) {
144144
}
145145

146146
if b < 0 {
147-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
147+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
148148
}
149149

150150
return MulUint64(a, uint64(b))
@@ -154,7 +154,7 @@ func MulInteger(a uint64, b int64) (uint64, error) {
154154
// It just checks overflow, if b is zero, a "divide by zero" panic throws.
155155
func DivInt64(a int64, b int64) (int64, error) {
156156
if a == math.MinInt64 && b == -1 {
157-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
157+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
158158
}
159159

160160
return a / b, nil
@@ -165,7 +165,7 @@ func DivInt64(a int64, b int64) (int64, error) {
165165
func DivUintWithInt(a uint64, b int64) (uint64, error) {
166166
if b < 0 {
167167
if a != 0 && uint64(-b) <= a {
168-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b)))
168+
return 0, ErrOverflow.GenByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%d, %d)", a, b))
169169
}
170170

171171
return 0, nil
@@ -179,7 +179,7 @@ func DivUintWithInt(a uint64, b int64) (uint64, error) {
179179
func DivIntWithUint(a int64, b uint64) (uint64, error) {
180180
if a < 0 {
181181
if uint64(-a) >= b {
182-
return 0, errors.Trace(ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b)))
182+
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%d, %d)", a, b))
183183
}
184184

185185
return 0, nil

0 commit comments

Comments
 (0)