Improve error messages in Js5ChannelHandler

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 59d75721d1
commit d7919da2a3
  1. 23
      archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt

@ -139,7 +139,14 @@ public class Js5ChannelHandler(
val removed = inFlightRequests.remove(request) val removed = inFlightRequests.remove(request)
if (!removed) { if (!removed) {
throw Exception("Received response for request not in-flight") val type = if (response.prefetch) {
"prefetch"
} else {
"urgent"
}
val archive = response.archive
val group = response.group
throw Exception("Received response for $type request (archive $archive group $group) not in-flight")
} }
if (response.archive == Js5Archive.ARCHIVESET && response.group == Js5Archive.ARCHIVESET) { if (response.archive == Js5Archive.ARCHIVESET && response.group == Js5Archive.ARCHIVESET) {
@ -207,9 +214,10 @@ public class Js5ChannelHandler(
} }
private fun processIndex(archive: Int, buf: ByteBuf) { private fun processIndex(archive: Int, buf: ByteBuf) {
val checksum = buf.crc32()
val entry = masterIndex!!.entries[archive] val entry = masterIndex!!.entries[archive]
if (buf.crc32() != entry.checksum) { if (checksum != entry.checksum) {
throw Exception("Index checksum invalid") throw Exception("Index $archive checksum invalid (expected ${entry.checksum}, actual $checksum)")
} }
Js5Compression.uncompress(buf.slice()).use { uncompressed -> Js5Compression.uncompress(buf.slice()).use { uncompressed ->
@ -217,7 +225,7 @@ public class Js5ChannelHandler(
indexes[archive] = index indexes[archive] = index
if (index.version != entry.version) { if (index.version != entry.version) {
throw Exception("Index version invalid") throw Exception("Index $archive version invalid (expected ${entry.version}, actual ${index.version})")
} }
val groups = runBlocking { val groups = runBlocking {
@ -230,10 +238,11 @@ public class Js5ChannelHandler(
} }
private fun processGroup(archive: Int, group: Int, buf: ByteBuf) { private fun processGroup(archive: Int, group: Int, buf: ByteBuf) {
val checksum = buf.crc32()
val entry = indexes[archive]!![group]!! val entry = indexes[archive]!![group]!!
if (checksum != entry.checksum) {
if (buf.crc32() != entry.checksum) { val expected = entry.checksum
throw Exception("Group checksum invalid") throw Exception("Archive $archive group $group checksum invalid (expected $expected, actual $checksum)")
} }
val uncompressed = Js5Compression.uncompressUnlessEncrypted(buf.slice()) val uncompressed = Js5Compression.uncompressUnlessEncrypted(buf.slice())

Loading…
Cancel
Save