Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 35ff224

Browse files
committed
Merge pull request #4 from kr/descriptive-error
return a more descriptive error
2 parents b0f2414 + 427f53c commit 35ff224

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

metrics.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func NewHistogram(name string, minValue, maxValue int64, sigfigs int) *Histogram
180180

181181
hist := &Histogram{
182182
hist: hdrhistogram.NewWindowed(5, minValue, maxValue, sigfigs),
183+
name: name,
183184
}
184185
histograms[name] = hist
185186

@@ -200,15 +201,22 @@ type Histogram struct {
200201
hist *hdrhistogram.WindowedHistogram
201202
m *hdrhistogram.Histogram
202203
rw sync.RWMutex
204+
205+
name string
203206
}
204207

205208
// RecordValue records the given value, or returns an error if the value is out
206209
// of range.
210+
// Returned error values are of type Error.
207211
func (h *Histogram) RecordValue(v int64) error {
208212
h.rw.Lock()
209213
defer h.rw.Unlock()
210214

211-
return h.hist.Current.RecordValue(v)
215+
err := h.hist.Current.RecordValue(v)
216+
if err != nil {
217+
return Error{h.name, err}
218+
}
219+
return nil
212220
}
213221

214222
func (h *Histogram) rotate() {
@@ -238,6 +246,16 @@ func (h *Histogram) valueAt(q float64) func() int64 {
238246
}
239247
}
240248

249+
// Error describes an error and the name of the metric where it occurred.
250+
type Error struct {
251+
Metric string
252+
Err error
253+
}
254+
255+
func (e Error) Error() string {
256+
return e.Metric + ": " + e.Err.Error()
257+
}
258+
241259
var (
242260
counters = make(map[string]uint64)
243261
counterFuncs = make(map[string]func() uint64)

0 commit comments

Comments
 (0)