Skip to content

Commit bf4c701

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

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ 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 failure.
215216
} catch (RuntimeException e) {
216217
collectors.remove(collector);
217218
CollectorRegistration reg = collectorMetadata.remove(collector);
@@ -244,6 +245,8 @@ public void register(MultiCollector collector) {
244245
}
245246

246247
multiCollectorMetadata.put(collector, registrations);
248+
// Catch RuntimeException broadly because collector methods (getPrometheusNames, getMetricType,
249+
// etc.) are user-implemented and could throw any RuntimeException. Ensures cleanup on failure.
247250
} catch (RuntimeException e) {
248251
multiCollectors.remove(collector);
249252
for (MultiCollectorRegistration registration : registrations) {

0 commit comments

Comments
 (0)