From d3951ff7c41428c30fcf47bfc6bded1d80d07eba Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Thu, 4 Dec 2025 15:35:11 +0100 Subject: [PATCH] LSP-306 [lsp] add some diagnostics GitOrigin-RevId: d1aa5b3cd4a6ad5e8ae842cd3d83a35bb558c373 --- .../lsp/implementation/protocolFraming.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/protocolFraming.kt b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/protocolFraming.kt index 59c596c8b0f8..16ab789e0ac6 100644 --- a/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/protocolFraming.kt +++ b/fleet/lsp.protocol/srcCommonMain/com/jetbrains/lsp/implementation/protocolFraming.kt @@ -69,22 +69,29 @@ private suspend fun ByteReader.readFrame(): JsonElement? { val line = readUTF8Line() if (line.isNullOrEmpty()) break readSomething = true - val (key, value) = line.split(':').map { it.trim() } - if (key == "Content-Length") { - contentLength = value.toInt() + try { + val (key, value) = line.split(':').map { it.trim() } + if (key == "Content-Length") { + contentLength = value.toInt() + } + } catch(x: Throwable) { + throw IllegalStateException("could not read header: $line", x) } } if (!readSomething) return null if (contentLength == -1) throw IllegalStateException("Content-Length header not found") readByteArray(contentLength) } - catch (e: Exception) { - when (e) { - is IOException -> return null - else -> throw e - } + catch (_: IOException) { + return null + } + val jsonStr = buf.decodeToStringUtf8() + return try { + LSP.json.decodeFromString(JsonElement.serializer(), jsonStr) + } + catch (x: Throwable) { + throw IllegalStateException("could not decode json: $jsonStr", x) } - return LSP.json.decodeFromString(JsonElement.serializer(), buf.decodeToStringUtf8()) } /**