Skip to content

Commit 8d7e154

Browse files
committed
fix(modelql): more detailed exception for unsupported cross-query streams
1 parent f472d93 commit 8d7e154

File tree

2 files changed

+14
-1
lines changed
  • modelql-core/src

2 files changed

+14
-1
lines changed

modelql-core/src/commonMain/kotlin/org/modelix/modelql/core/Query.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class QueryInput<E> : ProducingStep<E>(), IMonoStep<E> {
492492
}
493493

494494
override fun createStream(context: IStreamInstantiationContext): StepStream<E> {
495-
throw RuntimeException("The stream for the query input step is expected to be created by the query")
495+
throw IllegalArgumentException("Unsupported cross-query usage of $this in ${owner.query}")
496496
}
497497

498498
override fun canBeEmpty(): Boolean = false

modelql-core/src/commonTest/kotlin/org/modelix/modelql/core/ModelQLTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,19 @@ class ModelQLTest {
360360
assertEquals("Samsung Universe 9", result)
361361
}
362362

363+
@Test
364+
fun testIllegalCrossQueryStreams() = runTestWithTimeout {
365+
val ex = assertFailsWith(IllegalArgumentException::class) {
366+
remoteProductDatabaseQuery<String> { db ->
367+
// The `elements` query uses the outside `db` instead of the input `it`.
368+
// The query is only allowed to use values from its input, otherwise it wouldn't be cacheable.
369+
db.find({ db.products }, { it.id }, 3.asMono()).title
370+
}
371+
}
372+
val expectedMessage = "Unsupported cross-query usage of"
373+
assertEquals(expectedMessage, (ex.message ?: "").take(expectedMessage.length))
374+
}
375+
363376
@Test
364377
fun testFindAll() = runTestWithTimeout {
365378
val result: List<String> = remoteProductDatabaseQuery { db ->

0 commit comments

Comments
 (0)