From 9aa88a19f23e8314017104fe956a3af39c832313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kuchy=C5=88ka=20=28Anty=29?= Date: Thu, 31 Oct 2024 10:10:42 +0100 Subject: [PATCH 1/2] fix: use proper base type for flutter parse exceptions --- .../io/tolgee/exceptions/ImportCannotParseFileException.kt | 2 +- .../formats/flutter/in/FlutterArbFileParseException.kt | 5 ++++- .../io/tolgee/formats/flutter/in/FlutterArbFileParser.kt | 4 ---- .../io/tolgee/formats/flutter/in/FlutterArbFileProcessor.kt | 6 +++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/exceptions/ImportCannotParseFileException.kt b/backend/data/src/main/kotlin/io/tolgee/exceptions/ImportCannotParseFileException.kt index 00427e66b1..07c876f9e5 100644 --- a/backend/data/src/main/kotlin/io/tolgee/exceptions/ImportCannotParseFileException.kt +++ b/backend/data/src/main/kotlin/io/tolgee/exceptions/ImportCannotParseFileException.kt @@ -1,4 +1,4 @@ package io.tolgee.exceptions -class ImportCannotParseFileException(filename: String, causeMessage: String?, cause: Exception? = null) : +open class ImportCannotParseFileException(filename: String, causeMessage: String?, cause: Exception? = null) : BadRequestException(io.tolgee.constants.Message.CANNOT_PARSE_FILE, listOf(filename, causeMessage ?: ""), cause) diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParseException.kt b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParseException.kt index 5895cd9e7f..3b905a6e08 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParseException.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParseException.kt @@ -1,3 +1,6 @@ package io.tolgee.formats.flutter.`in` -class FlutterArbFileParseException(cause: Exception) : RuntimeException("Cannot parse arb file", cause) +import io.tolgee.exceptions.ImportCannotParseFileException + +class FlutterArbFileParseException(filename: String, cause: Exception) : + ImportCannotParseFileException(filename, "Cannot parse arb file", cause) diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt index 98c0f831ee..15f0466f0d 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt @@ -10,12 +10,8 @@ class FlutterArbFileParser( private val objectMapper: ObjectMapper, ) { fun parse(): FlutterArbModel { - try { val data = objectMapper.readValue>(bytes) return parseArbData(data) - } catch (e: Exception) { - throw FlutterArbFileParseException(e) - } } private fun parseArbData(data: Map): FlutterArbModel { diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileProcessor.kt b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileProcessor.kt index 1d424c68bb..7275c0db0c 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileProcessor.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileProcessor.kt @@ -33,7 +33,11 @@ class FlutterArbFileProcessor( } private val parsed by lazy { - FlutterArbFileParser(context.file.data, objectMapper).parse() + try { + FlutterArbFileParser(context.file.data, objectMapper).parse() + } catch (e: Exception) { + throw FlutterArbFileParseException(context.file.name, e) + } } fun convertMessage(text: String?): MessageConvertorResult { From adf53770ed7c2b5f35bd19a006484cdfa47afbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kuchy=C5=88ka=20=28Anty=29?= Date: Thu, 31 Oct 2024 10:37:26 +0100 Subject: [PATCH 2/2] fix: lint --- .../io/tolgee/formats/flutter/in/FlutterArbFileParser.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt index 15f0466f0d..2e391fb8ef 100644 --- a/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt +++ b/backend/data/src/main/kotlin/io/tolgee/formats/flutter/in/FlutterArbFileParser.kt @@ -10,8 +10,8 @@ class FlutterArbFileParser( private val objectMapper: ObjectMapper, ) { fun parse(): FlutterArbModel { - val data = objectMapper.readValue>(bytes) - return parseArbData(data) + val data = objectMapper.readValue>(bytes) + return parseArbData(data) } private fun parseArbData(data: Map): FlutterArbModel {