Skip to content

Commit ed2bc17

Browse files
committed
enhance error message for missing values
The error message "value not found in result set" was not helpful in identifying the failing metric. This change enhances the error message to include the metric name and the key that was not found, making it easier to debug user-defined aggregations. The new error message is: "value for metric <metric.Name> with key <metric.Value> not found in result set"
1 parent ab2ecea commit ed2bc17

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

internal/collector/collector.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ type Metric struct {
7676
var (
7777
//Only Gauge is a supported metric types
7878
ErrInvalidType = errors.New("unknown metric type provided. Only gauge is supported")
79-
//The value was not found in the aggregation result set
80-
ErrValueNotFound = errors.New("value not found in result set")
79+
8180
//No cached metric available
8281
ErrNotCached = errors.New("metric not available from cache")
8382
)
@@ -471,7 +470,7 @@ func (metric *Metric) getValue(result AggregationResult) (float64, error) {
471470
}
472471
}
473472

474-
return 0, ErrValueNotFound
473+
return 0, fmt.Errorf("value for metric %s with key %s not found in result set", metric.Name, metric.Value)
475474
}
476475

477476
func (metric *Metric) getLabels(result AggregationResult) ([]string, error) {

internal/collector/collector_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ func TestInitializeMetrics(t *testing.T) {
142142
aggregation: &Aggregation{
143143
Metrics: []*Metric{
144144
{
145-
Name: "simple_gauge_value_not_found",
146-
Type: "gauge",
145+
Name: "simple_gauge_value_not_found",
146+
Type: "gauge",
147+
Value: "total",
147148
},
148149
},
149150
Pipeline: "[{\"$match\":{\"foo\":\"bar\"}}]",
150151
},
151152
docs: []interface{}{AggregationResult{}},
152-
//error: "1 error occurred:\n\t* value not found in result set\n\n",
153+
//error: "value for metric simple_gauge_value_not_found with key total not found in result set",
153154
expected: ``,
154155
},
155156
{

0 commit comments

Comments
 (0)