Files
purchases-ios/Sources/Misc/FatalErrorUtil.swift
T
NachoSoto e445156071 FatalErrorUtil: don't override fatalError on release builds (#1736)
This hack is useful for tests, but since it's not needed in production, better to avoid compiling it and overriding Swift's `fatalError`.
2022-06-30 08:59:58 -07:00

38 lines
1.0 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// FatalErrorUtil.swift
//
// Created by Andrés Boedo on 9/16/21.
import Foundation
#if DEBUG
enum FatalErrorUtil {
fileprivate static var fatalErrorClosure: (String, StaticString, UInt) -> Never = defaultFatalErrorClosure
private static let defaultFatalErrorClosure = { Swift.fatalError($0, file: $1, line: $2) }
static func replaceFatalError(closure: @escaping (String, StaticString, UInt) -> Never) {
fatalErrorClosure = closure
}
static func restoreFatalError() {
fatalErrorClosure = defaultFatalErrorClosure
}
}
func fatalError(_ message: @autoclosure () -> String = "", file: StaticString = #fileID, line: UInt = #line) -> Never {
FatalErrorUtil.fatalErrorClosure(message(), file, line)
}
#endif