From 97f73a01da3e492f65e7b25c893757a79f80e971 Mon Sep 17 00:00:00 2001 From: Rena Briseno Date: Wed, 27 Jul 2022 09:57:59 -0700 Subject: [PATCH] Fix issue where EpoxyLogger asserts would unexpectedly crash in release builds (#115) In the same style as https://github.com/airbnb/lottie-ios/pull/1665, fixes an issue where `EpoxyLogger.shared.assertionFailure` and `EpoxyLogger.shared.assert` would unexpectedly crash in release builds. --- CHANGELOG.md | 4 +++- Sources/EpoxyCore/Logging/EpoxyLogger.swift | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0ab5c..d7ad856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,8 +32,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Gracefully support cases where a `SwiftUIMeasurementContainer` with an `intrinsicSize` `SwiftUIMeasurementContainerStrategy` has an intrinsic size that exceeds the proposed size by compressing rather than overflowing, which could result in broken layouts. -- Fixed intrinsic size invalidation triggered by a SwiftUI view from within a collection view +- Fixed intrinsic size invalidation triggered by a SwiftUI view from within a collection view cell by invalidating the enclosing collection view layout. +- Fixed an issue where `EpoxyLogger.shared.assertionFailure` and `EpoxyLogger.shared.assert` would + unexpectedly crash in release builds. ### Changed - Updated name of `Spacer` to `LayoutSpacer` to avoid name conflict with SwiftUI's `Spacer` diff --git a/Sources/EpoxyCore/Logging/EpoxyLogger.swift b/Sources/EpoxyCore/Logging/EpoxyLogger.swift index 555eb6c..c85240f 100644 --- a/Sources/EpoxyCore/Logging/EpoxyLogger.swift +++ b/Sources/EpoxyCore/Logging/EpoxyLogger.swift @@ -8,8 +8,19 @@ public final class EpoxyLogger { // MARK: Lifecycle public init( - assert: @escaping Assert = Swift.assert, - assertionFailure: @escaping AssertionFailure = Swift.assertionFailure, + assert: @escaping Assert = { condition, message, file, line in + // If we default to `Swift.assert` directly with `assert: Assert = Swift.assert`, + // the call will unexpectedly not respect the -O flag and will crash in release + // https://github.com/apple/swift/issues/60249 + Swift.assert(condition(), message(), file: file, line: line) + }, + assertionFailure: @escaping AssertionFailure = { message, file, line in + // If we default to `Swift.assertionFailure` directly with + // `assertionFailure: AssertionFailure = Swift.assertionFailure`, + // the call will unexpectedly not respect the -O flag and will crash in release + // https://github.com/apple/swift/issues/60249 + Swift.assertionFailure(message(), file: file, line: line) + }, warn: @escaping Warn = { message, _, _ in #if DEBUG // swiftlint:disable:next no_direct_standard_out_logs