Skip to content

Commit

Permalink
util/types: use GenByArgs for ErrOverflow. (pingcap#3038)
Browse files Browse the repository at this point in the history
ErrOverflow has changed to a format, we need to use GenByArgs to get a valid message.
  • Loading branch information
coocood authored Apr 12, 2017
1 parent f5270ad commit 2cce608
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (b *builtinConvSig) eval(row []types.Datum) (d types.Datum, err error) {

val, err := strconv.ParseUint(n, int(fromBase), 64)
if err != nil {
return d, errors.Trace(types.ErrOverflow)
return d, types.ErrOverflow.GenByArgs("BIGINT UNSINGED", n)
}
// See https://github.com/mysql/mysql-server/blob/5.7/strings/ctype-simple.c#L598
if signed {
Expand Down
8 changes: 4 additions & 4 deletions util/types/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func StrToInt(sc *variable.StatementContext, str string) (int64, error) {
validPrefix, err := getValidIntPrefix(sc, str)
iVal, err1 := strconv.ParseInt(validPrefix, 10, 64)
if err1 != nil {
return iVal, errors.Trace(ErrOverflow)
return iVal, ErrOverflow.GenByArgs("BIGINT", validPrefix)
}
return iVal, errors.Trace(err)
}
Expand All @@ -154,7 +154,7 @@ func StrToUint(sc *variable.StatementContext, str string) (uint64, error) {
}
uVal, err1 := strconv.ParseUint(validPrefix, 10, 64)
if err1 != nil {
return uVal, errors.Trace(ErrOverflow)
return uVal, ErrOverflow.GenByArgs("BIGINT UNSIGNED", validPrefix)
}
return uVal, errors.Trace(err)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func floatStrToIntStr(validFloat string) (string, error) {
}
if exp > 0 && int64(intCnt) > (math.MaxInt64-int64(exp)) {
// (exp + incCnt) overflows MaxInt64.
return validFloat, errors.Trace(ErrOverflow)
return validFloat, ErrOverflow.GenByArgs("BIGINT", validFloat)
}
intCnt += exp
if intCnt <= 0 {
Expand All @@ -220,7 +220,7 @@ func floatStrToIntStr(validFloat string) (string, error) {
extraZeroCount := intCnt - len(digits)
if extraZeroCount > 20 {
// Return overflow to avoid allocating too much memory.
return validFloat, errors.Trace(ErrOverflow)
return validFloat, ErrOverflow.GenByArgs("BIGINT", validFloat)
}
validInt = string(digits) + strings.Repeat("0", extraZeroCount)
}
Expand Down
2 changes: 1 addition & 1 deletion util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ func (d *Datum) convertToMysqlDecimal(sc *variable.StatementContext, target *Fie
prec, frac := dec.PrecisionAndFrac()
if prec-frac > target.Flen-target.Decimal {
dec = NewMaxOrMinDec(dec.IsNegative(), target.Flen, target.Decimal)
err = errors.Trace(ErrOverflow)
err = ErrOverflow.GenByArgs("DECIMAL", fmt.Sprintf("(%d, %d)", target.Flen, target.Decimal))
} else if frac != target.Decimal {
dec.Round(dec, target.Decimal)
if frac > target.Decimal {
Expand Down
6 changes: 3 additions & 3 deletions util/types/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getMaxFloat(flen int, decimal int) float64 {
func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
if math.IsNaN(f) {
// nan returns 0
return 0, ErrOverflow
return 0, ErrOverflow.GenByArgs("DOUBLE", "")
}

maxF := getMaxFloat(flen, decimal)
Expand All @@ -70,10 +70,10 @@ func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
var err error
if f > maxF {
f = maxF
err = ErrOverflow
err = ErrOverflow.GenByArgs("DOUBLE", "")
} else if f < -maxF {
f = -maxF
err = ErrOverflow
err = ErrOverflow.GenByArgs("DOUBLE", "")
}

return f, errors.Trace(err)
Expand Down

0 comments on commit 2cce608

Please sign in to comment.