Skip to content

Commit 844052a

Browse files
committed
Fix GroupBy not rethrowing errors from the upstream
1 parent 8bd8b31 commit 844052a

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Extensions to the Kotlin Flow library.
1111

1212
```groovy
1313
dependencies {
14-
implementation "com.github.akarnokd:kotlin-flow-extensions:0.0.11"
14+
implementation "com.github.akarnokd:kotlin-flow-extensions:0.0.12"
1515
}
1616
```
1717

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=com.github.akarnokd
2-
VERSION_NAME=0.0.11
2+
VERSION_NAME=0.0.12
33

44
POM_ARTIFACT_ID=kotlin-flow-extensions
55
POM_NAME=Kotlin Flow Extensions

src/main/kotlin/hu/akarnokd/kotlin/flow/impl/FlowGroupBy.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ internal class FlowGroupBy<T, K, V>(
8181
for (group in map.values) {
8282
group.error(ex)
8383
}
84+
throw ex
8485
}
8586
}
8687

src/test/kotlin/hu/akarnokd/kotlin/flow/impl/FlowGroupByTest.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlinx.coroutines.FlowPreview
2222
import kotlinx.coroutines.delay
2323
import kotlinx.coroutines.flow.*
2424
import kotlinx.coroutines.runBlocking
25+
import org.junit.Assert.assertThrows
2526
import org.junit.Ignore
2627
import org.junit.Test
2728

@@ -82,4 +83,31 @@ class FlowGroupByTest {
8283
.assertResultSet(1, 2)
8384
}
8485

86+
@Test
87+
fun mainErrorsNoItems() {
88+
assertThrows(IllegalStateException::class.java) {
89+
runBlocking {
90+
(1..10)
91+
.asFlow()
92+
.map { if(it < 5) throw IllegalStateException("oops") else it }
93+
.groupBy { it % 2 == 0 }
94+
.flatMapMerge { it }
95+
.collect()
96+
}
97+
}
98+
}
99+
100+
@Test
101+
fun mainErrorsSomeItems() {
102+
assertThrows(IllegalStateException::class.java) {
103+
runBlocking {
104+
(1..10)
105+
.asFlow()
106+
.map { if(it > 5) throw IllegalStateException("oops") else it }
107+
.groupBy { it % 2 == 0 }
108+
.flatMapMerge { it }
109+
.collect()
110+
}
111+
}
112+
}
85113
}

0 commit comments

Comments
 (0)