Merge pull request #1975 from hackskills/1971-out-of-bounds

Fixed out of bounds panic to show error
This commit is contained in:
Shaquille Wyan Que 2019-05-15 12:39:41 -05:00 committed by GitHub
commit 29e6bd29d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -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("%s: %s", intOutOfRangeError, err))
}
if elem.inList {
if elem.lastCond != ILLEGAL {

View file

@ -26,8 +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 intOutOfRangeError = "integer is not in signed 64-bit range"
// parser represents a parser for the PQL language.
type parser struct {
@ -71,7 +72,11 @@ func (p *parser) Parse() (*Query, error) {
p.Execute()
}()
if v != nil {
if strings.HasPrefix(v.(string), duplicateArgErrorMessage) {
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 {
panic(v)

View file

@ -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 {