I had to fix a couple of issues related to this today and when you have a bunch spread across the code is not that easy to know which one is the one trapping.
@mbrandonw would you consider adding more information into the optional assertion?
I quickly prototyped this:
extension Reducer {
public func optional(_ file: String = #file, _ line: Int = #line) -> Reducer<State?, Action, Environment> {
.init { state, action, environment in
if state == nil {
print("Nil optional reducer: \(file):\(line)")
}
return self.optional.run(&state, action, environment)
}
}
}
and it's already way more useful:
Nil optional reducer: .../Main/Main.swift:76
Fatal error: ....
Doing it in the library directly would be nicer since the message would be integrated in the assert. But I didn't want to open a PR without consulting since I'm afraid overloading the property with a function may cause some trouble.
What do you think?