Permalink
Browse files

metrics: counter: return error for -ve inc

  • Loading branch information...
1 parent 7261a7b commit 7643da8a5134111e460e1bc875a9900c04c659c7 @suyash suyash committed Aug 9, 2016
Showing with 4 additions and 0 deletions.
  1. +4 −0 metrics.go
View
@@ -617,6 +617,10 @@ func (c *PCPCounter) Set(val int64) error {
// Inc increases the stored counter's value by the passed increment
func (c *PCPCounter) Inc(val int64) error {
+ if val < 0 {
+ return errors.New("cannot decrement a counter")
+ }
+
v := c.Val()
v += val
return c.Set(v)

0 comments on commit 7643da8

Please sign in to comment.