Skip to content

Commit

Permalink
Fix issue where EpoxyLogger asserts would unexpectedly crash in relea…
Browse files Browse the repository at this point in the history
…se builds (#115)

In the same style as airbnb/lottie-ios#1665, fixes an issue where `EpoxyLogger.shared.assertionFailure` and `EpoxyLogger.shared.assert` would unexpectedly crash in release builds.
  • Loading branch information
renabriseno68 committed Jul 27, 2022
1 parent 3b223ce commit 97f73a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
15 changes: 13 additions & 2 deletions Sources/EpoxyCore/Logging/EpoxyLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97f73a0

Please sign in to comment.