All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.islandtime.parser.DateTimeParseException.kt Maven / Gradle / Ivy

The newest version!
package io.islandtime.parser

import io.islandtime.DateTimeException

class DateTimeParseException(
    message: String? = null,
    val parsedString: String? = null,
    val errorIndex: Int = 0,
    cause: Throwable? = null
) : DateTimeException(message, cause)

internal inline fun  throwParserFieldResolutionException(parsedText: String): Nothing {
    val objectType = T::class.simpleName ?: "Unknown"

    throw DateTimeParseException(
        "The provided parser was unable to supply the fields needed to resolve an object of type '$objectType'",
        parsedText
    )
}

internal inline fun  throwParserGroupResolutionException(
    expectedCount: Int,
    actualCount: Int,
    parsedText: String
): Nothing {
    val objectType = T::class.simpleName ?: "Unknown"

    throw DateTimeParseException(
        "The provided parser was unable resolve an object of type '$objectType'. Expected $expectedCount groups, got " +
            "$actualCount.",
        parsedText
    )
}

internal inline fun  List.expectingGroupCount(
    expected: Int,
    parsedText: String
): List {
    if (size != expected) {
        throwParserGroupResolutionException(2, size, parsedText)
    }
    return this
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy