From 11eaf1474e328fe98d3d231b5bbf2b411131f7b4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 23 Aug 2018 09:51:11 -0400 Subject: [PATCH] Add OWSProdExit(). --- SignalServiceKit/src/Util/OWSAsserts.h | 12 ++++++++ SignalServiceKit/src/Util/OWSSwiftUtils.swift | 30 +++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/SignalServiceKit/src/Util/OWSAsserts.h b/SignalServiceKit/src/Util/OWSAsserts.h index a78e31072..f6a10c50a 100755 --- a/SignalServiceKit/src/Util/OWSAsserts.h +++ b/SignalServiceKit/src/Util/OWSAsserts.h @@ -139,6 +139,18 @@ NS_ASSUME_NONNULL_BEGIN } while (NO) +#define OWSProdExit(_messageFormat, ...) \ + do { \ + OWSFail(_messageFormat, ##__VA_ARGS__); \ + exit(0); \ + } while (0) + +#define OWSCProdExit(_messageFormat, ...) \ + do { \ + OWSCFail(_messageFormat, ##__VA_ARGS__); \ + exit(0); \ + } while (NO) + // Avoids Clang analyzer warning: // Value stored to 'x' during it's initialization is never read #define SUPPRESS_DEADSTORE_WARNING(x) \ diff --git a/SignalServiceKit/src/Util/OWSSwiftUtils.swift b/SignalServiceKit/src/Util/OWSSwiftUtils.swift index c21a4ca08..4a46f45ae 100644 --- a/SignalServiceKit/src/Util/OWSSwiftUtils.swift +++ b/SignalServiceKit/src/Util/OWSSwiftUtils.swift @@ -15,12 +15,6 @@ public func assertOnQueue(_ queue: DispatchQueue) { } } -public func owsFail(_ message: String) { - Logger.error(message) - Logger.flush() - assertionFailure(message) -} - // Once we're on Swift4.2 we can mark this as inlineable // @inlinable public func AssertIsOnMainThread(file: String = #file, @@ -32,3 +26,27 @@ public func AssertIsOnMainThread(file: String = #file, return } } + +// Once we're on Swift4.2 we can mark this as inlineable +// @inlinable +public func owsFail(_ rawMessage: String, + file: String = #file, + function: String = #function, + line: Int = #line) { + // TODO: Format using owsFormatLogMessage() once it is merged. + let message = "\(file) \(function) \(line): \(rawMessage)" + Logger.error(message) + Logger.flush() + assertionFailure(message) +} + +// Once we're on Swift4.2 we can mark this as inlineable +// @inlinable +public func owsProdExit(_ rawMessage: String, + file: String = #file, + function: String = #function, + line: Int = #line) { + + owsFail(rawMessage, file: file, function: function, line: line) + fatalError() +}