From 98a864634ebae5fef9849f6b4f8c2dd8e5f78f3e Mon Sep 17 00:00:00 2001 From: Shaquille Wyan Que Date: Tue, 14 May 2019 16:58:03 -0500 Subject: [PATCH] fixed out of bounds panic to show error --- pql/ast.go | 2 +- pql/parser.go | 3 ++- pql/pqlpeg_test.go | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pql/ast.go b/pql/ast.go index 20b757946..e14a93fe1 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -160,7 +160,7 @@ func (q *Query) addNumVal(val string) { ival, err = strconv.ParseInt(val, 10, 64) } if err != nil { - panic(err) + panic(fmt.Sprintf("out of bounds: %s", err)) } if elem.inList { if elem.lastCond != ILLEGAL { diff --git a/pql/parser.go b/pql/parser.go index 6a28f560e..c9f92c61a 100644 --- a/pql/parser.go +++ b/pql/parser.go @@ -28,6 +28,7 @@ const timeFormat = "2006-01-02T15:04" // duplicateArgErrorMessage is used as an error string in the parser. const duplicateArgErrorMessage = "duplicate argument provided" +const parsingIntErrorMessage = "out of bounds" // parser represents a parser for the PQL language. type parser struct { @@ -71,7 +72,7 @@ func (p *parser) Parse() (*Query, error) { p.Execute() }() if v != nil { - if strings.HasPrefix(v.(string), duplicateArgErrorMessage) { + if strings.HasPrefix(v.(string), duplicateArgErrorMessage) || strings.HasPrefix(v.(string), parsingIntErrorMessage){ return nil, fmt.Errorf("%s", v) } else { panic(v) diff --git a/pql/pqlpeg_test.go b/pql/pqlpeg_test.go index a90d58a5d..c9db07407 100644 --- a/pql/pqlpeg_test.go +++ b/pql/pqlpeg_test.go @@ -333,6 +333,12 @@ func TestPEGErrors(t *testing.T) { { name: "RangeTimeOneStamp", input: "Row(a=4, 2010-07-04T00:00)"}, + { + name: "ArgOutOfBounds", + input: "Row(a=9223372036854775808)"}, + { + name: "ArgOutOfBoundsNeg", + input: "Row(a=-9223372036854775809)"}, } for i, test := range tests {