diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonPatch.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonPatch.kt index 2ea8665b..d8b4bf9d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonPatch.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/json/JsonPatch.kt @@ -21,15 +21,15 @@ enum class JsonPatch(val key: String) { if (inverse) { if (value == JsonNull.INSTANCE && get != JsonNull.INSTANCE) { - throw IllegalStateException("Expected $path to not contain anything") + throw JsonTestException("Expected $path to not contain anything") } else if (value != JsonNull.INSTANCE && value == get) { - throw IllegalStateException("Expected $path to not contain $value") + throw JsonTestException("Expected $path to not contain $value") } } else { if (value == JsonNull.INSTANCE && get == JsonNull.INSTANCE) { - throw IllegalStateException("Expected $path to contain anything") + throw JsonTestException("Expected $path to contain anything") } else if (value != JsonNull.INSTANCE && get == JsonNull.INSTANCE) { - throw IllegalStateException("Expected $path to contain '$value', but found nothing") + throw JsonTestException("Expected $path to contain '$value', but found nothing") } else if (value != JsonNull.INSTANCE && get != JsonNull.INSTANCE && value != get) { var text = get.toString() @@ -37,7 +37,7 @@ enum class JsonPatch(val key: String) { text = text.substring(0, 40) + "..." } - throw IllegalStateException("Expected $path to contain $value, but found $text") + throw JsonTestException("Expected $path to contain $value, but found $text") } } @@ -80,6 +80,8 @@ enum class JsonPatch(val key: String) { abstract fun apply(base: JsonElement, data: JsonObject): JsonElement + class JsonTestException(message: String) : IllegalStateException(message) + companion object { private val LOGGER = LogManager.getLogger() @@ -99,6 +101,8 @@ enum class JsonPatch(val key: String) { if (element is JsonObject) { try { base = apply(base, element) + } catch (err: JsonTestException) { + LOGGER.debug("Test condition failed in {} at index {}: {}", source, i, err.message) } catch (err: Throwable) { LOGGER.error("Error while applying JSON patch from $source at index $i: ${err.message}") } @@ -109,6 +113,9 @@ enum class JsonPatch(val key: String) { throw JsonSyntaxException("Expected JSON Object as patch data, got $sub") base = apply(base, sub) + } catch (err: JsonTestException) { + LOGGER.debug("Test condition failed in {} at index {} -> {}: {}", source, i, i2, err.message) + break } catch (err: Throwable) { LOGGER.error("Error while applying JSON patch from $source at index $i -> $i2: ${err.message}") break