Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yosemite: Log Fatal Errors to Sentry #2867

Merged
merged 4 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
ReferencedContainer = "container:WooCommerce.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-force-crash-logging 1"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
4 changes: 4 additions & 0 deletions Yosemite/Yosemite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
45ED4F16239E939A004F1BE3 /* TaxClassStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45ED4F15239E939A004F1BE3 /* TaxClassStoreTests.swift */; };
570B05CF246B6AAD00C186AE /* RetrieveProductReviewFromNoteUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 570B05CE246B6AAD00C186AE /* RetrieveProductReviewFromNoteUseCase.swift */; };
57150E1124F462D900E81611 /* TestKit in Frameworks */ = {isa = PBXBuildFile; productRef = 57150E1024F462D900E81611 /* TestKit */; };
571D7E3F251BB9FA00606E96 /* LogErrorAndExit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571D7E3E251BB9FA00606E96 /* LogErrorAndExit.swift */; };
5726456F250BD4E4005BBD7C /* OrdersUpsertUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5726456E250BD4E4005BBD7C /* OrdersUpsertUseCase.swift */; };
57264572250BE2E7005BBD7C /* OrdersUpsertUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57264571250BE2E7005BBD7C /* OrdersUpsertUseCaseTests.swift */; };
572F2B8D247312E4005A5F74 /* StorageManagerConcurrencyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 572F2B8C247312E4005A5F74 /* StorageManagerConcurrencyTests.swift */; };
Expand Down Expand Up @@ -340,6 +341,7 @@
45E18631237046CB009241F3 /* ShippingLine+ReadOnlyConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShippingLine+ReadOnlyConvertible.swift"; sourceTree = "<group>"; };
45ED4F15239E939A004F1BE3 /* TaxClassStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaxClassStoreTests.swift; sourceTree = "<group>"; };
570B05CE246B6AAD00C186AE /* RetrieveProductReviewFromNoteUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrieveProductReviewFromNoteUseCase.swift; sourceTree = "<group>"; };
571D7E3E251BB9FA00606E96 /* LogErrorAndExit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogErrorAndExit.swift; sourceTree = "<group>"; };
5726456E250BD4E4005BBD7C /* OrdersUpsertUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdersUpsertUseCase.swift; sourceTree = "<group>"; };
57264571250BE2E7005BBD7C /* OrdersUpsertUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdersUpsertUseCaseTests.swift; sourceTree = "<group>"; };
572F2B8C247312E4005A5F74 /* StorageManagerConcurrencyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageManagerConcurrencyTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1053,6 +1055,7 @@
933A27342222352500C2143A /* Logging.swift */,
743057B2218B69D100441A76 /* Queue.swift */,
02E4F5E323CD5628003B0010 /* NSOrderedSet+Array.swift */,
571D7E3E251BB9FA00606E96 /* LogErrorAndExit.swift */,
);
path = Internal;
sourceTree = "<group>";
Expand Down Expand Up @@ -1414,6 +1417,7 @@
749375042249691D007D85D1 /* Product+ReadOnlyConvertible.swift in Sources */,
CE43A90222A072D800A4FF29 /* ProductDownload+ReadOnlyConvertible.swift in Sources */,
B5C9DE182087FF0E006B910A /* Assert.swift in Sources */,
571D7E3F251BB9FA00606E96 /* LogErrorAndExit.swift in Sources */,
CE0DB6C0233EB3F300A27E7A /* OrderRefundCondensed+ReadOnlyConvertible.swift in Sources */,
0225512122FC2F3000D98613 /* OrderStatsV4Interval+Date.swift in Sources */,
2614E12A24C7451D007CEE60 /* LeaderboardStatsConverter.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Base/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Dispatcher {
assertMainThread()

guard processors[actionType.identifier] == nil else {
fatalError("An action type can only be handled by a single processor!")
logErrorAndExit("An action type can only be handled by a single processor!")
}

processors[actionType.identifier] = WeakProcessor(processor: processor)
Expand Down
4 changes: 2 additions & 2 deletions Yosemite/Yosemite/Base/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ open class Store: ActionsProcessor {
/// Subclasses should override this and register for supported Dispatcher Actions.
///
open func registerSupportedActions(in dispatcher: Dispatcher) {
fatalError("Override me!")
logErrorAndExit("Override me!")
}

/// This method is called for every Action. Subclasses should override this and deal with the Actions relevant to them.
///
open func onAction(_ action: Action) {
fatalError("Override me!")
logErrorAndExit("Override me!")
}
}

Expand Down
12 changes: 12 additions & 0 deletions Yosemite/Yosemite/Internal/LogErrorAndExit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

/// Logs the error in CocoaLumberjack and stops app execution.
///
/// Prefer to use this instead of `fatalError()` since messages in fatal errors are not shown
/// in Sentry. Using this method, Sentry will still only show “Fatal error” in the Issue message
/// but the `message` can now be accessed through the Encrypted Logging Console.
///
internal func logErrorAndExit(_ message: String, file: StaticString = #file, line: UInt = #line) -> Never {
DDLogError(message)
fatalError(message, file: file, line: line)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ extension OrderStatsV4Interval {
/// Returns the interval start date by parsing the `dateStart` string.
public func dateStart(timeZone: TimeZone) -> Date {
guard let date = createDateFormatter(timeZone: timeZone).date(from: dateStart) else {
fatalError("Failed to parse date: \(dateStart)")
logErrorAndExit("Failed to parse date: \(dateStart)")
}
return date
}

/// Returns the interval end date by parsing the `dateEnd` string.
public func dateEnd(timeZone: TimeZone) -> Date {
guard let date = createDateFormatter(timeZone: timeZone).date(from: dateEnd) else {
fatalError("Failed to parse date: \(dateEnd)")
logErrorAndExit("Failed to parse date: \(dateEnd)")
}
return date
}
Expand Down
2 changes: 1 addition & 1 deletion Yosemite/Yosemite/Stores/NotificationCountStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class NotificationCountStore: Store {
///
private lazy var fileURL: URL = {
guard let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
fatalError("Cannot find app document directory URL")
logErrorAndExit("Cannot find app document directory URL")
}
return documents.appendingPathComponent(Constants.notificationCountFileName)
}()
Expand Down