Skip to content

Commit 451d65c

Browse files
authored
Merge pull request #1432 from matrix-org/andy/assertion_failure
Add assertion failure macros
2 parents cd8840e + a962f19 commit 451d65c

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
lines changed

MatrixSDK/Data/RoomList/CoreData/MXCoreDataRoomListDataFetcher.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal class MXCoreDataRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
2929

3030
private let multicastDelegate: MXMulticastDelegate<MXRoomListDataFetcherDelegate> = MXMulticastDelegate()
3131

32-
private weak var session: MXSession?
3332
internal let fetchOptions: MXRoomListDataFetchOptions
3433
private lazy var dataUpdateThrottler: MXThrottler = {
3534
return MXThrottler(minimumDelay: 0.1, queue: .main)
@@ -114,10 +113,8 @@ internal class MXCoreDataRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
114113
return result
115114
}
116115

117-
internal init(session: MXSession?,
118-
fetchOptions: MXRoomListDataFetchOptions,
116+
internal init(fetchOptions: MXRoomListDataFetchOptions,
119117
store: MXRoomSummaryCoreDataContextableStore) {
120-
self.session = session
121118
self.fetchOptions = fetchOptions
122119
self.store = store
123120
super.init()

MatrixSDK/Data/RoomList/CoreData/MXCoreDataRoomListDataManager.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class MXCoreDataRoomListDataManager: NSObject, MXRoomListDataManager {
3636
session: session,
3737
spaceService: spaceService)
3838
}
39-
guard let session = session, let store = session.store else {
40-
fatalError("[MXCoreDataRoomListDataManager] No session or no store")
39+
guard let store = session?.store else {
40+
fatalError("[MXCoreDataRoomListDataManager] No session store")
4141
}
4242
guard let coreDataStore = store.roomSummaryStore as? MXRoomSummaryCoreDataContextableStore else {
4343
fatalError("[MXCoreDataRoomListDataManager] Session.store.roomSummaryStore is not CoreDataContextable")
@@ -46,8 +46,7 @@ public class MXCoreDataRoomListDataManager: NSObject, MXRoomListDataManager {
4646
assert(coreDataStore.mainManagedObjectContext.concurrencyType == .mainQueueConcurrencyType,
4747
"[MXCoreDataRoomListDataManager] Managed object context must have mainQueueConcurrencyType")
4848

49-
return MXCoreDataRoomListDataFetcher(session: session,
50-
fetchOptions: options,
49+
return MXCoreDataRoomListDataFetcher(fetchOptions: options,
5150
store: coreDataStore)
5251
}
5352
}

MatrixSDK/Utils/MXLog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@
3535
#define MXLogError(message, ...) { \
3636
[MXLogObjcWrapper logError:[NSString stringWithFormat: message, ##__VA_ARGS__] file:@__FILE__ function:[NSString stringWithFormat:@"%s", __FUNCTION__] line:__LINE__]; \
3737
}
38+
39+
#define MXLogFailure(message, ...) { \
40+
[MXLogObjcWrapper logFailure:[NSString stringWithFormat: message, ##__VA_ARGS__] file:@__FILE__ function:[NSString stringWithFormat:@"%s", __FUNCTION__] line:__LINE__]; \
41+
}

MatrixSDK/Utils/MXLog.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ private var logger: SwiftyBeaver.Type = {
118118
logger.error(message, file, function, line: line)
119119
}
120120

121+
public static func failure(_ message: @autoclosure () -> Any, _
122+
file: String = #file, _ function: String = #function, line: Int = #line, context: Any? = nil) {
123+
logger.error(message(), file, function, line: line, context: context)
124+
#if DEBUG
125+
assertionFailure("\(message())")
126+
#endif
127+
}
128+
129+
@available(swift, obsoleted: 5.4)
130+
@objc public static func logFailure(_ message: String, file: String, function: String, line: Int) {
131+
logger.error(message, file, function, line: line)
132+
#if DEBUG
133+
assertionFailure(message)
134+
#endif
135+
}
136+
121137
// MARK: - Private
122138

123139
fileprivate static func configureLogger(_ logger: SwiftyBeaver.Type, withConfiguration configuration: MXLogConfiguration) {

MatrixSDK/Utils/MXLogObjcWrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
3333

3434
+ (void)logError:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line;
3535

36+
+ (void)logFailure:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line;
37+
3638
@end
3739

3840
NS_ASSUME_NONNULL_END

MatrixSDK/Utils/MXLogObjcWrapper.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ + (void)logError:(NSString *)message file:(NSString *)file function:(NSString *)
4444
[MXLog logError:message file:file function:function line:line];
4545
}
4646

47+
+ (void)logFailure:(NSString *)message file:(NSString *)file function:(NSString *)function line:(NSUInteger)line
48+
{
49+
[MXLog logFailure:message file:file function:function line:line];
50+
}
51+
4752
@end

MatrixSDKTests/MXCoreDataRoomListDataManagerUnitTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ class MXCoreDataRoomListDataManagerUnitTests: XCTestCase {
187187
store.storeSummary(summary)
188188
}
189189

190-
let fetcher = MXCoreDataRoomListDataFetcher(session: nil,
191-
fetchOptions: basicFetchOptions,
190+
let fetcher = MXCoreDataRoomListDataFetcher(fetchOptions: basicFetchOptions,
192191
store: store)
193192
return fetcher
194193
}

0 commit comments

Comments
 (0)