Getting this weird error trying to deserialize fai...
# ktor
b
Getting this weird error trying to deserialize fairly long json response
Copy code
Exception in thread "main" io.ktor.utils.io.charsets.TooLongLineException: Line is longer than limit
    at io.ktor.utils.io.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invoke(ByteBufferChannel.kt:2022)
    at io.ktor.utils.io.ByteBufferChannel$readUTF8LineToUtf8Suspend$2.invoke(ByteBufferChannel.kt:1960)
    at io.ktor.utils.io.ByteBufferChannel.read$suspendImpl(ByteBufferChannel.kt:1648)
    at io.ktor.utils.io.ByteBufferChannel.read(ByteBufferChannel.kt)
    at io.ktor.utils.io.ByteBufferChannel.readUTF8LineToUtf8Suspend(ByteBufferChannel.kt:1960)
    at io.ktor.utils.io.ByteBufferChannel.access$readUTF8LineToUtf8Suspend(ByteBufferChannel.kt:23)
    at io.ktor.utils.io.ByteBufferChannel$readUTF8LineToUtf8Suspend$1.invokeSuspend(ByteBufferChannel.kt)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
Here's my code spawning the issue
Copy code
override suspend fun <T> FlowCollector<T>.emitItems(
    deserializer: KSerializer<T>,
    response: HttpResponse
  ) {
    val stream = response.bodyAsChannel().toInputStream()
    Json.decodeToSequence(
      stream = stream,
      deserializer = deserializer,
      format = DecodeSequenceMode.ARRAY_WRAPPED
    ).forEach { emit(it) }.also { stream.close() }
  }
Any clues what might be wrong (no kdocs on the exception)?
In case anyone else faces this in the future, the exception basically means your request url was too long (i had way too many parameters).
s
What defines "too long" here? 😅
b
Didn't capture that sadly, but that exception is only thrown once in the client codebase so you should be able to find the condition for it fairly easily.
Looks like it's Int.MAX_VALUE (2147483647) "most" of the time.
s
I am now scared, what was in that url
😆 1
b
Lots of ids returned in the previous request apparently, wasn't expecting to get the entire history of ids since the dawn of time returned in a single json object property...
😅 2