Skip to content

[gardening]: swap some preconditions with fatalError for better debugging #328

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

Merged
merged 1 commit into from
Mar 14, 2025
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
4 changes: 3 additions & 1 deletion Workflow/Sources/SubtreeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ extension WorkflowNode.SubtreeManager {

/// If the key was already in `used`, then a workflow of the same type was rendered multiple times
/// during this render pass with the same key. This is not allowed.
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)")
guard keyWasUnused else {
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)")
}

return child.render()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ extension UpdateChildScreenViewController where Self: UIViewController {
// We should only add the view controller if the old one was already within the parent.

if let parent = old.parent {
precondition(
parent == self,
"""
The parent of the child view controller must be \(self). Instead, it was \(parent). \
Please call `update(child:)` on the correct parent view controller.
"""
)
guard parent == self else {
fatalError(
"""
The parent of the child view controller must be \(self). Instead, it was \(parent). \
Please call `update(child:)` on the correct parent view controller.
"""
)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,15 @@ public struct ViewControllerDescription {
/// You must pass a view controller previously created by a compatible `ViewControllerDescription`
/// that passes `canUpdate(viewController:)`. Failure to do so will result in a fatal precondition.
public func update(viewController: UIViewController) {
precondition(
canUpdate(viewController: viewController),
"""
`ViewControllerDescription` was provided a view controller it cannot update: (\(viewController).

The view controller type (\(type(of: viewController)) is a compatible type to the expected type \(kind.viewControllerType)).
"""
)
guard canUpdate(viewController: viewController) else {
fatalError(
"""
`ViewControllerDescription` was provided a view controller it cannot update: (\(viewController).

The view controller type (\(type(of: viewController)) is a compatible type to the expected type \(kind.viewControllerType)).
"""
)
}

configureAncestor(of: viewController)

Expand Down
Loading