More logging!

This commit is contained in:
Shadowfacts 2022-10-08 15:12:10 -04:00
parent b7a4f7e30f
commit 5b116c0d4e
1 changed files with 30 additions and 3 deletions

View File

@ -38,7 +38,10 @@ actor TimelineLikeController<Item> {
private(set) var state = State.notLoadedInitial {
willSet {
precondition(state.canTransition(to: newValue))
guard state.canTransition(to: newValue) else {
logger.error("State \(self.state.debugDescription, privacy: .public) cannot transition to \(newValue.debugDescription, privacy: .public)")
preconditionFailure("cannot transition to state")
}
logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)")
}
}
@ -118,7 +121,10 @@ actor TimelineLikeController<Item> {
}
private func emit(event: Event) async {
precondition(state.canEmit(event: event))
guard state.canEmit(event: event) else {
logger.error("State \(self.state.debugDescription, privacy: .public) cannot emit event: \(event.debugDescription, privacy: .public)")
preconditionFailure("state cannot emit event")
}
switch event {
case .addLoadingIndicator:
await delegate.handleAddLoadingIndicator()
@ -227,7 +233,7 @@ actor TimelineLikeController<Item> {
}
}
enum Event {
enum Event: CustomDebugStringConvertible {
case addLoadingIndicator
case removeLoadingIndicator
case loadAllError(Error, LoadAttemptToken)
@ -236,6 +242,27 @@ actor TimelineLikeController<Item> {
case prependItems([Item], LoadAttemptToken)
case loadOlderError(Error, LoadAttemptToken)
case appendItems([Item], LoadAttemptToken)
var debugDescription: String {
switch self {
case .addLoadingIndicator:
return "addLoadingIndicator"
case .removeLoadingIndicator:
return "removeLoadingIndicator"
case .loadAllError(let error, let token):
return "loadAllError(\(error), \(token))"
case .replaceAllItems(_, let token):
return "replcaeAllItems(<omitted>, \(token))"
case .loadNewerError(let error, let token):
return "loadNewerError(\(error), \(token))"
case .prependItems(_, let token):
return "prependItems(<omitted>, \(token))"
case .loadOlderError(let error, let token):
return "loadOlderError(\(error), \(token))"
case .appendItems(_, let token):
return "appendItems(<omitted>, \(token))"
}
}
}
class LoadAttemptToken: Equatable {