Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 5aa60e0

Browse files
committed
sql: better errors for invalid argument number
Signed-off-by: Miguel Molina <[email protected]>
1 parent 2f71ae5 commit 5aa60e0

File tree

9 files changed

+14
-13
lines changed

9 files changed

+14
-13
lines changed

sql/expression/function/ceil_round_floor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type Round struct {
155155
func NewRound(args ...sql.Expression) (sql.Expression, error) {
156156
argLen := len(args)
157157
if argLen == 0 || argLen > 2 {
158-
return nil, sql.ErrInvalidArgumentNumber.New("1 or 2", argLen)
158+
return nil, sql.ErrInvalidArgumentNumber.New("ROUND", "1 or 2", argLen)
159159
}
160160

161161
var right sql.Expression

sql/expression/function/coalesce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Coalesce struct {
1515
// NewCoalesce creates a new Coalesce sql.Expression.
1616
func NewCoalesce(args ...sql.Expression) (sql.Expression, error) {
1717
if len(args) == 0 {
18-
return nil, sql.ErrInvalidArgumentNumber.New("1 or more", 0)
18+
return nil, sql.ErrInvalidArgumentNumber.New("COALESCE", "1 or more", 0)
1919
}
2020

2121
return &Coalesce{args}, nil

sql/expression/function/concat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var ErrConcatArrayWithOthers = errors.NewKind("can't concat a string array with
2020
// NewConcat creates a new Concat UDF.
2121
func NewConcat(args ...sql.Expression) (sql.Expression, error) {
2222
if len(args) == 0 {
23-
return nil, sql.ErrInvalidArgumentNumber.New("1 or more", 0)
23+
return nil, sql.ErrInvalidArgumentNumber.New("CONCAT", "1 or more", 0)
2424
}
2525

2626
for _, arg := range args {

sql/expression/function/concat_ws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ConcatWithSeparator struct {
1818
// NewConcatWithSeparator creates a new NewConcatWithSeparator UDF.
1919
func NewConcatWithSeparator(args ...sql.Expression) (sql.Expression, error) {
2020
if len(args) == 0 {
21-
return nil, sql.ErrInvalidArgumentNumber.New("1 or more", 0)
21+
return nil, sql.ErrInvalidArgumentNumber.New("CONCAT_WS", "1 or more", 0)
2222
}
2323

2424
for _, arg := range args {

sql/expression/function/json_extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type JSONExtract struct {
1818
// NewJSONExtract creates a new JSONExtract UDF.
1919
func NewJSONExtract(args ...sql.Expression) (sql.Expression, error) {
2020
if len(args) < 2 {
21-
return nil, sql.ErrInvalidArgumentNumber.New(2, len(args))
21+
return nil, sql.ErrInvalidArgumentNumber.New("JSON_EXTRACT", 2, len(args))
2222
}
2323

2424
return &JSONExtract{args[0], args[1:]}, nil

sql/expression/function/logarithm.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package function
22

33
import (
4+
"fmt"
45
"math"
56
"reflect"
6-
"fmt"
77

8-
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
9-
"gopkg.in/src-d/go-mysql-server.v0/sql"
108
"gopkg.in/src-d/go-errors.v1"
9+
"gopkg.in/src-d/go-mysql-server.v0/sql"
10+
"gopkg.in/src-d/go-mysql-server.v0/sql/expression"
1111
)
1212

1313
// ErrInvalidArgumentForLogarithm is returned when an invalid argument value is passed to a
@@ -94,7 +94,7 @@ type Log struct {
9494
func NewLog(args ...sql.Expression) (sql.Expression, error) {
9595
argLen := len(args)
9696
if argLen == 0 || argLen > 2 {
97-
return nil, sql.ErrInvalidArgumentNumber.New("1 or 2", argLen)
97+
return nil, sql.ErrInvalidArgumentNumber.New("LOG", "1 or 2", argLen)
9898
}
9999

100100
if argLen == 1 {

sql/expression/function/rpad_lpad.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"reflect"
66
"strings"
77

8-
"gopkg.in/src-d/go-mysql-server.v0/sql"
98
"gopkg.in/src-d/go-errors.v1"
9+
"gopkg.in/src-d/go-mysql-server.v0/sql"
1010
)
1111

1212
var ErrDivisionByZero = errors.NewKind("division by zero")
1313

1414
type padType rune
15+
1516
const (
1617
lPadType padType = 'l'
1718
rPadType padType = 'r'
@@ -28,7 +29,7 @@ func NewPadFunc(pType padType) func(e ...sql.Expression) (sql.Expression, error)
2829
func NewPad(pType padType, args ...sql.Expression) (sql.Expression, error) {
2930
argLen := len(args)
3031
if argLen != 3 {
31-
return nil, sql.ErrInvalidArgumentNumber.New("3", argLen)
32+
return nil, sql.ErrInvalidArgumentNumber.New(string(pType)+"pad", "3", argLen)
3233
}
3334

3435
return &Pad{args[0], args[1], args[2], pType}, nil

sql/expression/function/substring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewSubstring(args ...sql.Expression) (sql.Expression, error) {
3232
start = args[1]
3333
ln = args[2]
3434
default:
35-
return nil, sql.ErrInvalidArgumentNumber.New("2 or 3", len(args))
35+
return nil, sql.ErrInvalidArgumentNumber.New("SUBSTRING", "2 or 3", len(args))
3636
}
3737
return &Substring{str, start, ln}, nil
3838
}

sql/functionregistry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var ErrFunctionNotFound = errors.NewKind("function not found: %s")
99

1010
// ErrInvalidArgumentNumber is returned when the number of arguments to call a
1111
// function is different from the function arity.
12-
var ErrInvalidArgumentNumber = errors.NewKind("expecting %v arguments for calling this function, %d received")
12+
var ErrInvalidArgumentNumber = errors.NewKind("%s: expecting %v arguments for calling this function, %d received")
1313

1414
// Function is a function defined by the user that can be applied in a SQL
1515
// query.

0 commit comments

Comments
 (0)