Skip to content

Commit

Permalink
Replace specific bucket errors with generic ones
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Sep 16, 2022
1 parent 4035fa1 commit dc39cbd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions docs/usage/expressions.md
Expand Up @@ -335,11 +335,11 @@ The following error strings may be returned while compiling or evaluating your e

```go
const (
ErrorBucket = "<BUCKET-ERROR>" // Unable to bucket from given value (wrong type)
ErrorBucketSize = "<BUCKET-SIZE>" // Unable to get the size of the bucket (wrong type)
ErrorType = "<BAD-TYPE>" // Error parsing the principle value of the input because of unexpected type
ErrorParsing = "<PARSE-ERROR>" // Error parsing the principle value of the input
ErrorArgCount = "<ARGN>" // Function to not support a variation with the given argument count
ErrorArgName = "<NAME>" // A variable accessed by a given name does not exist
ErrorType = "<BAD-TYPE>" // Error parsing the principle value of the input because of unexpected type
ErrorParsing = "<PARSE-ERROR>" // Error parsing the principle value of the input (non-numeric)
ErrorArgCount = "<ARGN>" // Function to not support a variation with the given argument count
ErrorConst = "<CONST>" // Expected constant value
ErrorEnum = "<ENUM>" // A given value is not contained within a set
ErrorArgName = "<NAME>" // A variable accessed by a given name does not exist
)
```
12 changes: 6 additions & 6 deletions pkg/expressions/stdlib/errors.go
@@ -1,10 +1,10 @@
package stdlib

const (
ErrorBucket = "<BUCKET-ERROR>" // Unable to bucket from given value (wrong type)
ErrorBucketSize = "<BUCKET-SIZE>" // Unable to get the size of the bucket (wrong type)
ErrorType = "<BAD-TYPE>" // Error parsing the principle value of the input because of unexpected type
ErrorParsing = "<PARSE-ERROR>" // Error parsing the principle value of the input
ErrorArgCount = "<ARGN>" // Function to not support a variation with the given argument count
ErrorArgName = "<NAME>" // A variable accessed by a given name does not exist
ErrorType = "<BAD-TYPE>" // Error parsing the principle value of the input because of unexpected type
ErrorParsing = "<PARSE-ERROR>" // Error parsing the principle value of the input (non-numeric)
ErrorArgCount = "<ARGN>" // Function to not support a variation with the given argument count
ErrorConst = "<CONST>" // Expected constant value
ErrorEnum = "<ENUM>" // A given value is not contained within a set
ErrorArgName = "<NAME>" // A variable accessed by a given name does not exist
)
4 changes: 2 additions & 2 deletions pkg/expressions/stdlib/funcsCommon.go
Expand Up @@ -26,12 +26,12 @@ func kfBucket(args []KeyBuilderStage) KeyBuilderStage {
return KeyBuilderStage(func(context KeyBuilderContext) string {
val, err := strconv.Atoi(args[0](context))
if err != nil {
return ErrorBucket
return ErrorType
}

bucketSize, err := strconv.Atoi(args[1](context))
if err != nil {
return ErrorBucketSize
return ErrorType
}

return strconv.Itoa((val / bucketSize) * bucketSize)
Expand Down
4 changes: 2 additions & 2 deletions pkg/expressions/stdlib/funcsTime.go
Expand Up @@ -214,7 +214,7 @@ func timeBucketToFormat(name string) string {
} else if isPartialString(name, "years") {
return "2006"
}
return ErrorBucket
return ErrorEnum
}

// {func <time> <bucket> [format:auto] [tz:utc]}
Expand Down Expand Up @@ -269,7 +269,7 @@ func kfTimeAttr(args []KeyBuilderStage) KeyBuilderStage {

attrFunc, hasAttrFunc := attrType[strings.ToUpper(attrName)]
if !hasAttrFunc {
return stageError(ErrorBucket)
return stageError(ErrorEnum)
}

return KeyBuilderStage(func(context KeyBuilderContext) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/expressions/stdlib/funcs_test.go
Expand Up @@ -59,7 +59,7 @@ func TestBucket(t *testing.T) {
mockContext("1000", "1200", "1234"),
"{bucket {0} 1000} {bucket {1} 1000} {bucket {2} 1000} {bucket {2} 100}",
"1000 1000 1000 1200")
testExpression(t, mockContext(), "{bucket abc 100} {bucket 1}", "<BUCKET-ERROR> <ARGN>")
testExpression(t, mockContext(), "{bucket abc 100} {bucket 1}", "<BAD-TYPE> <ARGN>")
}

func TestExpBucket(t *testing.T) {
Expand Down

0 comments on commit dc39cbd

Please sign in to comment.