fixed out of bounds panic to show error

This commit is contained in:
Shaquille Wyan Que 2019-05-14 16:58:03 -05:00
parent 5f22aa3765
commit 98a864634e
3 changed files with 9 additions and 2 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("out of bounds: %s", err))
}
if elem.inList {
if elem.lastCond != ILLEGAL {

View file

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

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 {