Add asserts
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user