Skip to content

Commit

Permalink
Improve handling of blank input in duration parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Nov 15, 2022
1 parent 01f7ce8 commit 4d7a871
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/xyz/jpenilla/runtask/util/durations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ private val UNITS = mapOf(
*/
@Throws(InvalidDurationException::class)
internal fun parseDuration(input: String): Duration {
if (input.trim().isEmpty()) {
throw InvalidDurationException.noInput()
if (input.isBlank()) {
throw InvalidDurationException.noInput(input)
}
if (input.length < 2) {
throw InvalidDurationException.invalidInput(input)
Expand Down Expand Up @@ -72,8 +72,8 @@ internal class InvalidDurationException private constructor(
Example input strings: ["1d", "12h", "1m", "30s"]
""".trimIndent()

fun noInput(): InvalidDurationException =
InvalidDurationException("Cannot parse a Duration from an empty input string.\n$infoMessage")
fun noInput(input: String): InvalidDurationException =
InvalidDurationException("Cannot parse a Duration from a blank input string '$input'.\n$infoMessage")

fun invalidInput(input: String, cause: Throwable? = null) =
InvalidDurationException("Cannot parse a Duration from input '$input'.\n$infoMessage", cause)
Expand Down

0 comments on commit 4d7a871

Please sign in to comment.