From f1514a4c74daaa403ddf647935670fd2997c1343 Mon Sep 17 00:00:00 2001 From: Christian Priebe Date: Mon, 10 Feb 2020 19:11:28 +0000 Subject: [PATCH] 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. --- Sources/CoreMetrics/Metrics.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/CoreMetrics/Metrics.swift b/Sources/CoreMetrics/Metrics.swift index 8caefcc..0074236 100644 --- a/Sources/CoreMetrics/Metrics.swift +++ b/Sources/CoreMetrics/Metrics.swift @@ -346,7 +346,7 @@ public enum MetricsSystem { /// - factory: A factory that given an identifier produces instances of metrics handlers such as `CounterHandler`, `RecorderHandler` and `TimerHandler`. public static func bootstrap(_ factory: MetricsFactory) { self.lock.withWriterLock { - precondition(!self.initialized, "metrics system can only be initialized once per process. currently used factory: \(self.factory)") + precondition(!self.initialized, "metrics system can only be initialized once per process. currently used factory: \(self._factory)") self._factory = factory self.initialized = true }