Improve error reporting when reading snapshot version
diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/restore/Restore.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/restore/Restore.kt
index 1fc0e3e..1677613 100644
--- a/storage/lib/src/main/java/org/calyxos/backup/storage/restore/Restore.kt
+++ b/storage/lib/src/main/java/org/calyxos/backup/storage/restore/Restore.kt
@@ -154,13 +154,13 @@
@Throws(IOException::class, GeneralSecurityException::class)
internal fun InputStream.readVersion(expectedVersion: Int? = null): Int {
val version = read()
- if (version == -1) throw IOException()
+ if (version == -1) throw IOException("File empty!")
if (expectedVersion != null && version != expectedVersion) {
throw GeneralSecurityException("Expected version $expectedVersion, not $version")
}
if (version > Backup.VERSION) {
// TODO maybe throw a different exception here and tell the user?
- throw IOException()
+ throw IOException("Got version $version which is higher than what is supported.")
}
return version
}