Skip to content
Snippets Groups Projects
Unverified Commit f56c598a authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

If there is no fallback appconfig yet, abort early to show a more accurate...

If there is no fallback appconfig yet, abort early to show a more accurate error (download error vs "no app config" error). (#1293)

Co-authored-by: default avatarharambasicluka <64483219+harambasicluka@users.noreply.github.com>
parent 0f3a420d
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,12 @@ class AppConfigProvider @Inject constructor( ...@@ -58,7 +58,12 @@ class AppConfigProvider @Inject constructor(
downloadAppConfig() downloadAppConfig()
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e, "Failed to download latest AppConfig.") Timber.w(e, "Failed to download latest AppConfig.")
null if (configStorage.isAppConfigAvailable) {
null
} else {
Timber.e("No fallback available, rethrowing!")
throw e
}
} }
val newConfigParsed = try { val newConfigParsed = try {
......
...@@ -13,6 +13,9 @@ class AppConfigStorage @Inject constructor( ...@@ -13,6 +13,9 @@ class AppConfigStorage @Inject constructor(
private val configDir = File(context.filesDir, "appconfig_storage") private val configDir = File(context.filesDir, "appconfig_storage")
private val configFile = File(configDir, "appconfig") private val configFile = File(configDir, "appconfig")
val isAppConfigAvailable: Boolean
get() = configFile.exists() && configFile.length() > MIN_VALID_CONFIG_BYTES
var appConfigRaw: ByteArray? var appConfigRaw: ByteArray?
get() { get() {
Timber.v("get() AppConfig") Timber.v("get() AppConfig")
...@@ -36,4 +39,9 @@ class AppConfigStorage @Inject constructor( ...@@ -36,4 +39,9 @@ class AppConfigStorage @Inject constructor(
configFile.delete() configFile.delete()
} }
} }
companion object {
// The normal config is ~512B+, we just need to check for a non 0 value, 128 is fine.
private const val MIN_VALID_CONFIG_BYTES = 128
}
} }
...@@ -38,6 +38,7 @@ class AppConfigProviderTest : BaseIOTest() { ...@@ -38,6 +38,7 @@ class AppConfigProviderTest : BaseIOTest() {
testDir.mkdirs() testDir.mkdirs()
testDir.exists() shouldBe true testDir.exists() shouldBe true
every { appConfigStorage.isAppConfigAvailable } answers { mockConfigStorage != null }
every { appConfigStorage.appConfigRaw } answers { mockConfigStorage } every { appConfigStorage.appConfigRaw } answers { mockConfigStorage }
every { appConfigStorage.appConfigRaw = any() } answers { mockConfigStorage = arg(0) } every { appConfigStorage.appConfigRaw = any() } answers { mockConfigStorage = arg(0) }
} }
......
...@@ -36,6 +36,21 @@ class AppConfigStorageTest : BaseIOTest() { ...@@ -36,6 +36,21 @@ class AppConfigStorageTest : BaseIOTest() {
private fun createStorage() = AppConfigStorage(context) private fun createStorage() = AppConfigStorage(context)
@Test
fun `config availability is determined by file existence and min size`() {
storageDir.mkdirs()
val storage = createStorage()
storage.isAppConfigAvailable shouldBe false
configPath.createNewFile()
storage.isAppConfigAvailable shouldBe false
configPath.writeBytes(ByteArray(128) { 1 })
storage.isAppConfigAvailable shouldBe false
configPath.writeBytes(ByteArray(129) { 1 })
storage.isAppConfigAvailable shouldBe true
}
@Test @Test
fun `simple read and write config`() { fun `simple read and write config`() {
configPath.exists() shouldBe false configPath.exists() shouldBe false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment