mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
Merge pull request #1975 from hackskills/1971-out-of-bounds
Fixed out of bounds panic to show error
This commit is contained in:
commit
29e6bd29d7
3 changed files with 14 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue