Skip to content

Commit d1d4c09

Browse files
committed
add comments about use of RuntimeException:
Signed-off-by: Jay DeLuca <jaydeluca4@gmail.com>
1 parent 831645c commit d1d4c09

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/PrometheusRegistry.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ public void register(Collector collector) {
211211
collectorMetadata.put(
212212
collector, new CollectorRegistration(prometheusName, normalizedLabels));
213213
}
214-
214+
// Catch RuntimeException broadly because collector methods (getPrometheusName, getMetricType,
215+
// etc.) are user-implemented and could throw any RuntimeException. Ensures cleanup on
216+
// failure.
215217
} catch (RuntimeException e) {
216218
collectors.remove(collector);
217219
CollectorRegistration reg = collectorMetadata.remove(collector);
@@ -244,6 +246,10 @@ public void register(MultiCollector collector) {
244246
}
245247

246248
multiCollectorMetadata.put(collector, registrations);
249+
// Catch RuntimeException broadly because collector methods (getPrometheusNames,
250+
// getMetricType,
251+
// etc.) are user-implemented and could throw any RuntimeException. Ensures cleanup on
252+
// failure.
247253
} catch (RuntimeException e) {
248254
multiCollectors.remove(collector);
249255
for (MultiCollectorRegistration registration : registrations) {

0 commit comments

Comments
 (0)