tpl: Modify error messages of after, first, and last
authorBaibhav Vatsa <baibhavvatsa@gmail.com>
Fri, 11 Oct 2019 18:51:24 +0000 (13:51 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 12 Oct 2019 16:07:46 +0000 (18:07 +0200)
Modified the messages functions after, first, and last threw on being passed invalid parameters (index or limit) to be more standardised and resemble what Go compiler would throw.

Fixes #6415

tpl/collections/collections.go

index 95079436fde618fdb8b6e42b91b3718b02a1370d..df8aaa6c7dbd54070e302d52b461548a7f6a2108 100644 (file)
@@ -61,7 +61,7 @@ func (ns *Namespace) After(index interface{}, seq interface{}) (interface{}, err
        }
 
        if indexv < 0 {
-               return nil, errors.New("can't return negative/empty count of items from sequence")
+               return nil, errors.New("sequence bounds out of range [" + cast.ToString(indexv) + ":]")
        }
 
        seqv := reflect.ValueOf(seq)
@@ -219,7 +219,7 @@ func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, err
        }
 
        if limitv < 0 {
-               return nil, errors.New("can't return negative count of items from sequence")
+               return nil, errors.New("sequence length must be non-negative")
        }
 
        seqv := reflect.ValueOf(seq)
@@ -379,7 +379,7 @@ func (ns *Namespace) Last(limit interface{}, seq interface{}) (interface{}, erro
        }
 
        if limitv < 0 {
-               return nil, errors.New("can't return negative/empty count of items from sequence")
+               return nil, errors.New("sequence length must be non-negative")
        }
 
        seqv := reflect.ValueOf(seq)