diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 9be5310..22ea1c3 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -113,6 +113,13 @@ func IsNil(v interface{}) bool { return v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil()) } +// MustBeTrue panics when condition is false +func MustBeTrue(condition bool, errorStr string) { + if !condition { + panic(errorStr) + } +} + // MustBe panics with errorStr error, if v interface is not of reflect kind func MustBe(v interface{}, kind reflect.Kind, errorStr string) { if reflect.TypeOf(v).Kind() != kind { @@ -165,6 +172,7 @@ func ErrorCatch(err *error) { } } +// StringSliceContains checks if slice of strings contains a string func StringSliceContains(strings []string, contains string) bool { for _, str := range strings { if str == contains { diff --git a/postgres/functions.go b/postgres/functions.go index 6993de4..ddd01db 100644 --- a/postgres/functions.go +++ b/postgres/functions.go @@ -69,7 +69,7 @@ var COUNT = jet.COUNT // EVERY is aggregate function. Returns true if all input values are true, otherwise false var EVERY = jet.EVERY -// MAXf is aggregate function. Returns maximum value of expression across all input values +// MAX is aggregate function. Returns maximum value of expression across all input values var MAX = jet.MAX // MAXf is aggregate function. Returns maximum value of float expression across all input values diff --git a/qrm/scan_context.go b/qrm/scan_context.go index 8141ed7..e3f7f40 100644 --- a/qrm/scan_context.go +++ b/qrm/scan_context.go @@ -212,9 +212,7 @@ func (s *scanContext) rowElem(index int) interface{} { valuer, ok := s.row[index].(driver.Valuer) - if !ok { - panic("jet: internal error, scan value doesn't implement driver.Valuer") - } + utils.MustBeTrue(ok, "jet: internal error, scan value doesn't implement driver.Valuer") value, err := valuer.Value() diff --git a/qrm/utill.go b/qrm/utill.go index 20b8b54..7791f9a 100644 --- a/qrm/utill.go +++ b/qrm/utill.go @@ -50,9 +50,8 @@ func getSliceElemPtrAt(slicePtrValue reflect.Value, index int) reflect.Value { } func appendElemToSlice(slicePtrValue reflect.Value, objPtrValue reflect.Value) error { - if slicePtrValue.IsNil() { - panic("jet: internal, slice is nil") - } + utils.MustBeTrue(!slicePtrValue.IsNil(), "jet: internal, slice is nil") + sliceValue := slicePtrValue.Elem() sliceElemType := sliceValue.Type().Elem()