Skip to content

Commit bcd3b0e

Browse files
committed
fix(model-server-lib): Errors weren't reported, only Exceptions
1 parent 2320701 commit bcd3b0e

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

model-server-lib/src/main/kotlin/org/modelix/model/server/light/LightModelServer.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,21 @@ class LightModelServer @JvmOverloads constructor(val port: Int, val rootNodeProv
267267
for (frame in incoming) {
268268
when (frame) {
269269
is Frame.Text -> {
270-
val json = frame.readText()
271-
LOG.trace { "incoming message: ${json.take(5000)}" }
272-
val message = MessageFromClient.fromJson(json)
273-
message.query?.let { session.replaceQuery(it) }
274-
val ops = message.operations ?: emptyList()
275-
val response = if (ops.isNotEmpty()) {
276-
withContext(Dispatchers.Main) { // write access in MPS is only allowed from EDT
277-
getArea().executeWrite { session.applyUpdate(ops, message.changeSetId) }
270+
val response = try {
271+
val json = frame.readText()
272+
LOG.trace { "incoming message: ${json.take(5000)}" }
273+
val message = MessageFromClient.fromJson(json)
274+
message.query?.let { session.replaceQuery(it) }
275+
val ops = message.operations ?: emptyList()
276+
if (ops.isNotEmpty()) {
277+
withContext(Dispatchers.Main) { // write access in MPS is only allowed from EDT
278+
getArea().executeWrite { session.applyUpdate(ops, message.changeSetId) }
279+
}
280+
} else {
281+
getArea().executeRead { session.applyUpdate(ops, message.changeSetId) }
278282
}
279-
} else {
280-
getArea().executeRead { session.applyUpdate(ops, message.changeSetId) }
283+
} catch (ex: Throwable) {
284+
MessageFromServer(exception = ExceptionData(ex))
281285
}
282286
send(response.toJson())
283287
}
@@ -340,17 +344,13 @@ class LightModelServer @JvmOverloads constructor(val port: Int, val rootNodeProv
340344

341345
@Synchronized
342346
fun applyUpdate(operations: List<OperationData>, changeSetId: ChangeSetId?): MessageFromServer {
343-
try {
344-
val updateSession = UpdateSession()
345-
operations.forEach { updateSession.applyOperation(it) }
346-
return MessageFromServer(
347-
version = createUpdate(),
348-
replacedIds = updateSession.replacedIds,
349-
appliedChangeSet = changeSetId,
350-
)
351-
} catch (ex: Exception) {
352-
return MessageFromServer(exception = ExceptionData(ex))
353-
}
347+
val updateSession = UpdateSession()
348+
operations.forEach { updateSession.applyOperation(it) }
349+
return MessageFromServer(
350+
version = createUpdate(),
351+
replacedIds = updateSession.replacedIds,
352+
appliedChangeSet = changeSetId,
353+
)
354354
}
355355

356356
private inner class UpdateSession() {

0 commit comments

Comments
 (0)