Skip to content

Commit

Permalink
Fix error handling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hkusu committed Dec 12, 2024
1 parent fb2c3dd commit c4c076f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tart-core/src/commonMain/kotlin/io/yumemi/tart/core/TartStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
processMiddleware { onInit(this@TartStore, coroutineScope.coroutineContext) }
onStateEntered(initialState)
} catch (t: Throwable) {
if (t is MiddlewareError) {
if (t is InternalError) {
throw t.original
}
throw t
Expand All @@ -110,7 +110,7 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
onStateEntered(nextState)
}
} catch (t: Throwable) {
if (t is MiddlewareError) {
if (t is InternalError) {
throw t.original
}
onErrorOccurred(currentState, t)
Expand All @@ -133,7 +133,7 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
onStateEntered(nextState, inErrorHandling = inErrorHandling)
}
} catch (t: Throwable) {
if (t is MiddlewareError) {
if (t is InternalError) {
throw t.original
}
if (inErrorHandling) {
Expand All @@ -159,7 +159,7 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
onStateEntered(nextState, inErrorHandling = true)
}
} catch (t: Throwable) {
if (t is MiddlewareError) {
if (t is InternalError) {
throw t.original
}
throw t
Expand Down Expand Up @@ -192,7 +192,7 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
try {
latestState(nextState)
} catch (t: Throwable) {
onError(t)
throw InternalError(t)
}
processMiddleware { afterStateChange(nextState, state) }
}
Expand All @@ -218,9 +218,9 @@ open class TartStore<S : State, A : Action, E : Event> internal constructor(
}
}
} catch (t: Throwable) {
throw MiddlewareError(t)
throw InternalError(t)
}
}

private class MiddlewareError(val original: Throwable) : Throwable(original)
private class InternalError(val original: Throwable) : Throwable(original)
}

0 comments on commit c4c076f

Please sign in to comment.