From 97408589e18ecebef7fa380e019c43f5a24e1be7 Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Fri, 8 Aug 2025 16:38:42 +0200 Subject: change walk to use exceptions instead of error strings --- src/main/kotlin/Connection.kt | 12 ++++-------- src/main/kotlin/ProtocolTranslator.kt | 6 ++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/Connection.kt b/src/main/kotlin/Connection.kt index 659dd41..cb93533 100644 --- a/src/main/kotlin/Connection.kt +++ b/src/main/kotlin/Connection.kt @@ -1,5 +1,6 @@ import except.MsizeValueTooBigException import except.RErrorException +import except.UnaccessibleFileException import except.UnknownVersionException import java.io.IOException import java.math.BigInteger @@ -141,7 +142,7 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { this.pathInfo.addPath(PathInfo.Path(aname.split("/"), fid, qid)) } - override fun walk(fid: UInt, newfid: UInt, wname: List): String? { + override fun walk(fid: UInt, newfid: UInt, wname: List) { val nwname = wname.size val omsg = OutMessage(NinePMessageType.TWALK, this.tagGen.generate(), listOf("fid", "newfid", "nwname"), mapOf( @@ -157,16 +158,12 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { for (wn in wname) { // write wname elements OutMessage.writeString(this.tl, wn) } - val checkErr = checkedInMessage(omsg.tag) - if (checkErr.first != null) { - return checkErr.first - } - val imsg = checkErr.second!! + val imsg = checkedInMessage(omsg.tag) imsg.applyField(InMessage.Field("nwqid", InMessage.Field.Type.INTEGER, 2u)) val nwqid = imsg.fieldsInt["nwqid"]!!.toInt() if (nwqid < nwname) { - return "cannot access ${wname.slice(0..nwqid).joinToString(separator = "/")}" + throw UnaccessibleFileException(wname.slice(0..nwqid).joinToString(separator = "/")) } imsg.applyField(InMessage.Field("qids", InMessage.Field.Type.RAW, (nwqid * 13).toUInt())) val rawQids = imsg.fieldsRaw["qids"]!! @@ -183,7 +180,6 @@ class Connection(transLay: TransportLayer) : ProtocolTranslator { } this.pathInfo.removeFID(fid) this.pathInfo.addPath(PathInfo.Path(wname, newfid, qids.last())) - return null } override fun open(path: String) { diff --git a/src/main/kotlin/ProtocolTranslator.kt b/src/main/kotlin/ProtocolTranslator.kt index 1b45252..bf29131 100644 --- a/src/main/kotlin/ProtocolTranslator.kt +++ b/src/main/kotlin/ProtocolTranslator.kt @@ -67,9 +67,11 @@ interface ProtocolTranslator { * @param newfid The proposed FID, which is going to be associated with the result of walking the hierarchy. It must * be not in use, unless it is the same as [fid]. * @param wname The successive path name elements which describe the file to walk to. - * @return a possible error. + * @throws except.InvalidMessageException if the received message is invalid. + * @throws except.RErrorException if the received message is an R-error message. + * @throws except.UnaccessibleFileException if [wname] contains one or more files that do not exist. */ - fun walk(fid: UInt, newfid: UInt, wname: List): String? + fun walk(fid: UInt, newfid: UInt, wname: List) /** * Prepare an FID for I/O on an existing file. -- cgit v1.2.3