summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorEdoardo La Greca2025-08-07 19:32:41 +0200
committerEdoardo La Greca2025-08-07 19:32:41 +0200
commit60a9b89d01babe1d261d42a698ea906f4b293b59 (patch)
tree5cb4356c9b986d6c5caaab477ab88bf1b36a3189 /src/main
parent273ac61769dc4a8c025f6fbee8779c8859d25672 (diff)
change checkedInMessage to throw exceptions instead of returning errors
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/Connection.kt22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt
index 1cef2d3..48394e0 100644
--- a/src/main/kotlin/Connection.kt
+++ b/src/main/kotlin/Connection.kt
@@ -51,25 +51,25 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator {
}
/**
- * Handy function to create an [InMessage] instance and check for errors. It uses [tl] and [maxSize] for instancing
- * the [InMessage] class.
+ * Handy function to create an [InMessage] instance and check for errors. After successfully using this function, it
+ * is guaranteed that both no error occurred while reading the incoming message and the message is not of type
+ * R-error.
+ *
+ * It uses [tl] and [maxSize] for instancing the [InMessage] class.
*
* @return A pair of: (1) a nullable string (which can be: `null` if no error occurred, empty if an error occurred
* with no message, or non-empty with the error message) and (2) the optional [InMessage] instance (null if an error
* occurred).
+ * @throws InvalidMessageException if the received message is invalid.
+ * @throws RErrorException if the received message is an R-error message.
*/
- private fun checkedInMessage(reqTag: UShort): Pair<String?, InMessage?> {
- val imsg: InMessage
- try {
- imsg = InMessage(this.tl, this.maxSize, reqTag)
- } catch (ime: InvalidMessageException) {
- return Pair(ime.message!!, null)
- }
+ private fun checkedInMessage(reqTag: UShort): InMessage {
+ val imsg = InMessage(this.tl, this.maxSize, reqTag)
if (imsg.type == NinePMessageType.RERROR) {
imsg.applyField(InMessage.Field("ename", InMessage.Field.Type.STRING, 0u))
- return Pair(imsg.fieldsStr["ename"]!!, null)
+ throw RErrorException(imsg.fieldsStr["ename"])
}
- return Pair(null, imsg)
+ return imsg
}
override fun version(msize: UInt, version: String): String? {