Fix display of evaluation errors thrown by command convert/transformAll (#1431)

This commit is contained in:
Jen Basch
2026-02-20 07:51:33 -08:00
committed by GitHub
parent e07868b404
commit 08712e8b26
4 changed files with 97 additions and 28 deletions

View File

@@ -942,7 +942,52 @@ class CliCommandRunnerTest {
assertThrows<CliktError> {
runToStdout(CliBaseOptions(sourceModules = listOf(moduleUri)), listOf("hi"))
}
assertThat(exc.message).isEqualTo("oops!")
assertThat(exc.message).contains("oops!")
}
@Test
fun `convert with eval error`() {
val moduleUri =
writePklFile(
"cmd.pkl",
renderOptions +
"""
class Options {
@Argument { convert = (it) -> it.noSuchMethod() }
foo: String
}
"""
.trimIndent(),
)
val exc =
assertThrows<CliktError> {
runToStdout(CliBaseOptions(sourceModules = listOf(moduleUri)), listOf("hi"))
}
assertThat(exc.message).contains("Cannot find method `noSuchMethod` in class `String`.")
}
@Test
fun `convert with stack overflow`() {
val moduleUri =
writePklFile(
"cmd.pkl",
renderOptions +
"""
const function overflow(it) = overflow(it)
class Options {
@Argument { convert = (it) -> overflow(it) }
foo: String
}
"""
.trimIndent(),
)
val exc =
assertThrows<CliktError> {
runToStdout(CliBaseOptions(sourceModules = listOf(moduleUri)), listOf("hi"))
}
assertThat(exc.message).contains("A stack overflow occurred.")
}
@Test