From 5100eba70f2dd01d73a6ee18c3dba9fcb02ccb07 Mon Sep 17 00:00:00 2001 From: Matthias Urhahn <matthias.urhahn@sap.com> Date: Fri, 5 Feb 2021 09:12:34 +0100 Subject: [PATCH] Nicer error messages if a value is missing in an *_environments.json (#2283) --- .../environment/EnvironmentSetup.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/environment/EnvironmentSetup.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/environment/EnvironmentSetup.kt index 729096de6..63f923540 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/environment/EnvironmentSetup.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/environment/EnvironmentSetup.kt @@ -86,17 +86,24 @@ class EnvironmentSetup @Inject constructor( val targetEnvKey = if (environmentJson.has(currentEnvironment.rawKey)) { currentEnvironment.rawKey } else { - Timber.e("Tried to use unavailable environment: $variableKey on $currentEnvironment") + Timber.e("Tried to use unavailable environment: $currentEnvironment") Type.PRODUCTION.rawKey } - environmentJson + + val value = environmentJson .getAsJsonObject(targetEnvKey) .getAsJsonPrimitive(variableKey.rawKey) + + return@run if (value != null) { + Timber.v("getEnvironmentValue(endpoint=%s): %s", variableKey, value) + value + } else { + throw IllegalStateException("$currentEnvironment:$variableKey is missing in your *_environment.json") + } } catch (e: Exception) { - Timber.e(e, "Failed to retrieve endpoint URL for $currentEnvironment:$variableKey") - throw IllegalStateException("Failed to setup test environment", e) + throw IllegalStateException("Failed to retrieve $currentEnvironment:$variableKey", e) } - }.also { Timber.v("getEndpointUrl(endpoint=%s): %s", variableKey, it) } + } val submissionCdnUrl: String get() = getEnvironmentValue(SUBMISSION).asString -- GitLab