Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use proper base type for flutter parse exceptions #2655

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ class FlutterArbFileParser(
private val objectMapper: ObjectMapper,
) {
fun parse(): FlutterArbModel {
try {
val data = objectMapper.readValue<Map<String, Any>>(bytes)
return parseArbData(data)
} catch (e: Exception) {
throw FlutterArbFileParseException(e)
}
val data = objectMapper.readValue<Map<String, Any>>(bytes)
return parseArbData(data)
}

private fun parseArbData(data: Map<String, Any>): FlutterArbModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading