From 98a864634ebae5fef9849f6b4f8c2dd8e5f78f3e Mon Sep 17 00:00:00 2001 From: Shaquille Wyan Que Date: Tue, 14 May 2019 16:58:03 -0500 Subject: [PATCH 1/4] 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 { From b770167db66aea5205152e54beb7fdffeecf14ab Mon Sep 17 00:00:00 2001 From: Shaquille Wyan Que Date: Wed, 15 May 2019 10:52:15 -0500 Subject: [PATCH 2/4] fixed formatting --- pql/parser.go | 6 +++--- pql/pqlpeg_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pql/parser.go b/pql/parser.go index c9f92c61a..8c3b608c9 100644 --- a/pql/parser.go +++ b/pql/parser.go @@ -26,9 +26,9 @@ import ( // timeFormat is the go-style time format used to parse string dates. const timeFormat = "2006-01-02T15:04" -// duplicateArgErrorMessage is used as an error string in the parser. +// error strings in the parser const duplicateArgErrorMessage = "duplicate argument provided" -const parsingIntErrorMessage = "out of bounds" +const outOfBoundsErrorMessage = "out of bounds" // parser represents a parser for the PQL language. type parser struct { @@ -72,7 +72,7 @@ func (p *parser) Parse() (*Query, error) { p.Execute() }() if v != nil { - if strings.HasPrefix(v.(string), duplicateArgErrorMessage) || strings.HasPrefix(v.(string), parsingIntErrorMessage){ + if strings.HasPrefix(v.(string), duplicateArgErrorMessage) || strings.HasPrefix(v.(string), outOfBoundsErrorMessage) { return nil, fmt.Errorf("%s", v) } else { panic(v) diff --git a/pql/pqlpeg_test.go b/pql/pqlpeg_test.go index c9db07407..3ceff075d 100644 --- a/pql/pqlpeg_test.go +++ b/pql/pqlpeg_test.go @@ -333,7 +333,7 @@ func TestPEGErrors(t *testing.T) { { name: "RangeTimeOneStamp", input: "Row(a=4, 2010-07-04T00:00)"}, - { + { name: "ArgOutOfBounds", input: "Row(a=9223372036854775808)"}, { From 6ba6218ae439ac3f420b8d077fc9ba572eb4def9 Mon Sep 17 00:00:00 2001 From: Shaquille Wyan Que Date: Wed, 15 May 2019 11:22:04 -0500 Subject: [PATCH 3/4] changed out of range error message name and fixed formatting --- pql/ast.go | 2 +- pql/parser.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pql/ast.go b/pql/ast.go index e14a93fe1..49503474c 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(fmt.Sprintf("out of bounds: %s", err)) + panic(fmt.Sprintf("%s: %s", intOutOfRangeError, err)) } if elem.inList { if elem.lastCond != ILLEGAL { diff --git a/pql/parser.go b/pql/parser.go index 8c3b608c9..cef8a9b9b 100644 --- a/pql/parser.go +++ b/pql/parser.go @@ -28,7 +28,7 @@ const timeFormat = "2006-01-02T15:04" // error strings in the parser const duplicateArgErrorMessage = "duplicate argument provided" -const outOfBoundsErrorMessage = "out of bounds" +const intOutOfRangeError = "integer is not in signed 64-bit range" // parser represents a parser for the PQL language. type parser struct { @@ -72,7 +72,8 @@ func (p *parser) Parse() (*Query, error) { p.Execute() }() if v != nil { - if strings.HasPrefix(v.(string), duplicateArgErrorMessage) || strings.HasPrefix(v.(string), outOfBoundsErrorMessage) { + errorMessage := v.(string) + if strings.HasPrefix(errorMessage, duplicateArgErrorMessage) || strings.HasPrefix(errorMessage, intOutOfRangeError) { return nil, fmt.Errorf("%s", v) } else { panic(v) From 44088d4f29654537ee9ca9259ab705fcff055fda Mon Sep 17 00:00:00 2001 From: Shaquille Wyan Que Date: Wed, 15 May 2019 12:11:55 -0500 Subject: [PATCH 4/4] added check for unexpected parser error --- pql/parser.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pql/parser.go b/pql/parser.go index cef8a9b9b..e733038d7 100644 --- a/pql/parser.go +++ b/pql/parser.go @@ -72,7 +72,10 @@ func (p *parser) Parse() (*Query, error) { p.Execute() }() if v != nil { - errorMessage := v.(string) + errorMessage, ok := v.(string) + if !ok { + return nil, fmt.Errorf("unexpected parser error of type %T: %[1]v", v) + } if strings.HasPrefix(errorMessage, duplicateArgErrorMessage) || strings.HasPrefix(errorMessage, intOutOfRangeError) { return nil, fmt.Errorf("%s", v) } else {