Add asserts

pull/50/head
Koitharu 4 years ago
parent 551a1d70ae
commit 11f19b1f76
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -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
}

@ -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)
}

Loading…
Cancel
Save