Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
9f583f85
Commit
9f583f85
authored
Jul 05, 2019
by
Christian Sadilek
Committed by
Sebastian Kaspari
Jul 05, 2019
Browse files
Issue #3563: Introduce StoreException for errors caught in Store/Reducer
parent
32f69c0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
components/browser/state/src/test/java/mozilla/components/browser/state/store/BrowserStoreExceptionTest.kt
View file @
9f583f85
...
...
@@ -7,11 +7,11 @@ package mozilla.components.browser.state.store
import
androidx.test.ext.junit.runners.AndroidJUnit4
import
mozilla.components.browser.state.action.TabListAction
import
mozilla.components.browser.state.state.createTab
import
mozilla.components.lib.state.StoreException
import
mozilla.components.support.test.ext.joinBlocking
import
org.junit.Test
import
org.junit.runner.RunWith
import
org.robolectric.shadows.ShadowLooper
import
java.lang.IllegalStateException
// These tests are in a separate class because they needs to run with
// Robolectric (different runner, slower) while all other tests only
...
...
@@ -30,7 +30,7 @@ class BrowserStoreExceptionTest {
// Wait for the main looper to process the re-thrown exception.
ShadowLooper
.
idleMainLooper
()
}
catch
(
e
:
IllegalStat
eException
)
{
}
catch
(
e
:
Stor
eException
)
{
val
cause
=
e
.
cause
if
(
cause
!=
null
)
{
throw
cause
...
...
components/lib/state/src/main/java/mozilla/components/lib/state/Store.kt
View file @
9f583f85
...
...
@@ -48,7 +48,7 @@ open class Store<S : State, A : Action>(
// We want exceptions in the reducer to crash the app and not get silently ignored. Therefore we rethrow the
// exception on the main thread.
Handler
(
Looper
.
getMainLooper
()).
postAtFrontOfQueue
{
throw
IllegalStat
eException
(
"Exception while reducing state"
,
throwable
)
throw
Stor
eException
(
"Exception while reducing state"
,
throwable
)
}
// Once an exception happened we do not want to accept any further actions. So let's cancel the scope which
...
...
@@ -141,3 +141,9 @@ open class Store<S : State, A : Action>(
}
}
}
/**
* Exception for otherwise unhandled errors caught while reducing state or
* while managing/notifying observers.
*/
class
StoreException
(
val
msg
:
String
,
val
e
:
Throwable
?
=
null
)
:
Exception
(
msg
,
e
)
components/lib/state/src/test/java/mozilla/components/lib/state/StoreExceptionTest.kt
View file @
9f583f85
...
...
@@ -15,7 +15,7 @@ import org.robolectric.shadows.ShadowLooper
class
StoreExceptionTest
{
// This test is in a separate class because it needs to run with Robolectric (different runner, slower) while all
// other tests only need a Java VM (fast).
@Test
(
expected
=
java
.
lang
.
IllegalStat
eException
::
class
)
@Test
(
expected
=
Stor
eException
::
class
)
fun
`Exception
in
reducer
will
be
rethrown
on
main
thread`
()
{
val
throwingReducer
:
(
TestState
,
TestAction
)
->
TestState
=
{
_
,
_
->
throw
IllegalStateException
(
"Not reducing today"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment