Skip to content

Commit fddbc41

Browse files
authored
[gardening]: swap some preconditions with fatalError for better debugging (#328)
it was pointed out that `precondition` failure messages are generally not displayed in crash reports, so `fatalError` may be a better tool to handle terminating conditions. this change swaps out usage of `precondition` with `fatalError` for this reason.
1 parent 577f028 commit fddbc41

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Workflow/Sources/SubtreeManager.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ extension WorkflowNode.SubtreeManager {
230230

231231
/// If the key was already in `used`, then a workflow of the same type was rendered multiple times
232232
/// during this render pass with the same key. This is not allowed.
233-
precondition(keyWasUnused, "Child workflows of the same type must be given unique keys. Duplicate workflows of type \(Child.self) were encountered with the key \"\(key)\" in \(WorkflowType.self)")
233+
guard keyWasUnused else {
234+
fatalError("Child workflows of the same type must be given unique keys. Duplicate workflows of type \(Child.self) were encountered with the key \"\(key)\" in \(WorkflowType.self)")
235+
}
234236

235237
return child.render()
236238
}

WorkflowUI/Sources/ViewControllerDescription/UIViewController+Extensions.swift

+8-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ extension UpdateChildScreenViewController where Self: UIViewController {
6262
// We should only add the view controller if the old one was already within the parent.
6363

6464
if let parent = old.parent {
65-
precondition(
66-
parent == self,
67-
"""
68-
The parent of the child view controller must be \(self). Instead, it was \(parent). \
69-
Please call `update(child:)` on the correct parent view controller.
70-
"""
71-
)
65+
guard parent == self else {
66+
fatalError(
67+
"""
68+
The parent of the child view controller must be \(self). Instead, it was \(parent). \
69+
Please call `update(child:)` on the correct parent view controller.
70+
"""
71+
)
72+
}
7273

7374
// Begin the transition: Signal the new vc will begin moving in, and the old one, out.
7475

WorkflowUI/Sources/ViewControllerDescription/ViewControllerDescription.swift

+9-8
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,15 @@ public struct ViewControllerDescription {
131131
/// You must pass a view controller previously created by a compatible `ViewControllerDescription`
132132
/// that passes `canUpdate(viewController:)`. Failure to do so will result in a fatal precondition.
133133
public func update(viewController: UIViewController) {
134-
precondition(
135-
canUpdate(viewController: viewController),
136-
"""
137-
`ViewControllerDescription` was provided a view controller it cannot update: (\(viewController).
138-
139-
The view controller type (\(type(of: viewController)) is a compatible type to the expected type \(kind.viewControllerType)).
140-
"""
141-
)
134+
guard canUpdate(viewController: viewController) else {
135+
fatalError(
136+
"""
137+
`ViewControllerDescription` was provided a view controller it cannot update: (\(viewController).
138+
139+
The view controller type (\(type(of: viewController)) is a compatible type to the expected type \(kind.viewControllerType)).
140+
"""
141+
)
142+
}
142143

143144
configureAncestor(of: viewController)
144145

0 commit comments

Comments
 (0)