File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1
1
package io.modelcontextprotocol.kotlin.sdk.shared
2
2
3
+ import io.github.oshai.kotlinlogging.KotlinLogging
3
4
import io.modelcontextprotocol.kotlin.sdk.JSONRPCMessage
4
5
import kotlinx.io.Buffer
5
6
import kotlinx.io.indexOf
@@ -9,6 +10,9 @@ import kotlinx.io.readString
9
10
* Buffers a continuous stdio stream into discrete JSON-RPC messages.
10
11
*/
11
12
public class ReadBuffer {
13
+
14
+ private val logger = KotlinLogging .logger { }
15
+
12
16
private val buffer: Buffer = Buffer ()
13
17
14
18
public fun append (chunk : ByteArray ) {
@@ -37,7 +41,13 @@ public class ReadBuffer {
37
41
string
38
42
}
39
43
}
40
- return deserializeMessage(line)
44
+ try {
45
+ return deserializeMessage(line)
46
+ } catch (e: Exception ) {
47
+ logger.error(e) { " Failed to deserialize message from line: $line \n Skipping..." }
48
+ }
49
+
50
+ return null
41
51
}
42
52
43
53
public fun clear () {
You can’t perform that action at this time.
0 commit comments