Add rudimentary parse error processing

This commit is contained in:
Sergey Dudoladov
2018-11-08 19:01:52 +01:00
parent c6df079d2b
commit 85aef0f30b
3 changed files with 26 additions and 9 deletions
+6 -5
View File
@@ -3,6 +3,7 @@ package util
import (
"crypto/md5" // #nosec we need it to for PostgreSQL md5 passwords
"encoding/hex"
"fmt"
"math/rand"
"regexp"
"strings"
@@ -130,17 +131,17 @@ func Coalesce(val, defaultVal string) string {
}
// RequestIsSmallerThanLimit
func RequestIsSmallerThanLimit(requestStr, limitStr string) bool {
func RequestIsSmallerThanLimit(requestStr, limitStr string) (bool, error) {
request, err := resource.ParseQuantity(requestStr)
if err != nil {
return false, fmt.Errorf("could not parse memory request %v : %v", requestStr, err)
}
limit, err2 := resource.ParseQuantity(requestStr)
limit, err2 := resource.ParseQuantity(limitStr)
if err2 != nil {
return false, fmt.Errorf("could not parse memory limit %v : %v", limitStr, err2)
}
return request.Cmp(limit) == -1
return request.Cmp(limit) == -1, nil
}