Skip to content

Commit cdf9b63

Browse files
fix(lapis): return proper error message when lineage definition from SILO is invalid YAML (#1117)
resolves #1104
1 parent 38554e2 commit cdf9b63

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lapis/src/main/kotlin/org/genspectrum/lapis/silo/SiloClient.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package org.genspectrum.lapis.silo
33
import com.fasterxml.jackson.annotation.JsonInclude
44
import com.fasterxml.jackson.databind.ObjectMapper
55
import com.fasterxml.jackson.module.kotlin.readValue
6-
import mu.KotlinLogging
76
import org.genspectrum.lapis.controller.LapisHeaders.REQUEST_ID
7+
import org.genspectrum.lapis.log
88
import org.genspectrum.lapis.logging.RequestContext
99
import org.genspectrum.lapis.logging.RequestIdContext
1010
import org.genspectrum.lapis.response.InfoData
@@ -22,8 +22,6 @@ import java.net.http.HttpResponse
2222
import java.net.http.HttpResponse.BodyHandlers
2323
import java.util.stream.Stream
2424

25-
private val log = KotlinLogging.logger {}
26-
2725
@Component
2826
class SiloClient(
2927
private val cachedSiloClient: CachedSiloClient,
@@ -129,7 +127,20 @@ open class CachedSiloClient(
129127
tryToReadSiloErrorFromBody = ::tryToReadSiloErrorFromString,
130128
) { it.GET() }
131129

132-
return yamlObjectMapper.objectMapper.readValue(response.body())
130+
val body = response.body()
131+
try {
132+
return yamlObjectMapper.objectMapper.readValue(body)
133+
} catch (e: Exception) {
134+
log.error {
135+
val truncateLength = 1000
136+
val bodyToLog = when {
137+
body.length > truncateLength -> body.substring(0, truncateLength) + "... (truncated)"
138+
else -> body
139+
}
140+
"Failed to parse lineage definition from SILO, it was: '$bodyToLog'"
141+
}
142+
throw RuntimeException("Failed to parse lineage definition from SILO: ${e.message}", e)
143+
}
133144
}
134145

135146
private fun <ResponseBodyType> send(

lapis/src/test/kotlin/org/genspectrum/lapis/silo/SiloClientTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,26 @@ class SiloClientTest(
479479
)
480480
}
481481

482+
@Test
483+
fun `GIVEN silo returns invalid lineage definition file THEN returns appropriate error`() {
484+
val columnName = "test_column"
485+
MockServerClient("localhost", MOCK_SERVER_PORT)
486+
.`when`(
487+
request()
488+
.withMethod("GET")
489+
.withPath("/lineageDefinition/$columnName")
490+
.withHeader("X-Request-Id", REQUEST_ID_VALUE),
491+
)
492+
.respond(
493+
response()
494+
.withStatusCode(200)
495+
.withBody(""),
496+
)
497+
498+
val exception = assertThrows<RuntimeException> { underTest.getLineageDefinition(columnName) }
499+
assertThat(exception.message, containsString("Failed to parse lineage definition from SILO: "))
500+
}
501+
482502
companion object {
483503
@JvmStatic
484504
val mutationActions = listOf(

0 commit comments

Comments
 (0)