Skip to content

Commit f1514a4

Browse files
authored
Bugfix: Print correct error message if bootstrap is called multiple times (#57)
MetricsSystem.bootstrap verifies that the metric system has not been previously initialized. Otherwise it should fail with a corresponding error message. The precondition error message includes the name of the currently used factory and for that accesses self.factory. However, because bootstrap already holds self.lock as a writer lock, self.factory fails to get it as a reader and crashes with a less useful precondition error message. This commit ensures that the correct error message is printed.
1 parent aa197a1 commit f1514a4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/CoreMetrics/Metrics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public enum MetricsSystem {
346346
/// - factory: A factory that given an identifier produces instances of metrics handlers such as `CounterHandler`, `RecorderHandler` and `TimerHandler`.
347347
public static func bootstrap(_ factory: MetricsFactory) {
348348
self.lock.withWriterLock {
349-
precondition(!self.initialized, "metrics system can only be initialized once per process. currently used factory: \(self.factory)")
349+
precondition(!self.initialized, "metrics system can only be initialized once per process. currently used factory: \(self._factory)")
350350
self._factory = factory
351351
self.initialized = true
352352
}

0 commit comments

Comments
 (0)