Add asserts

This commit is contained in:
2022-09-07 13:05:23 +03:00
parent 551a1d70ae
commit 11f19b1f76
2 changed files with 11 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
package org.koitharu.kotatsu.parsers.util
fun <T : Any> T?.assertNotNull(name: String): T? {
assert(this != null) {
"Value $name is null"
}
return this
}

View File

@@ -68,10 +68,13 @@ fun String.toAbsoluteUrl(domain: String): String = when {
}
fun DateFormat.tryParse(str: String?): Long = if (str.isNullOrEmpty()) {
assert(false) { "Date string is null or empty" }
0L
} else {
runCatching {
parse(str)?.time ?: 0L
}.onFailure {
assert(false) { "Cannot parse date $str: ${it.message}" }
}.getOrDefault(0L)
}