Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Each error should be its own subtype #15

Closed
edgarsi opened this issue Aug 14, 2022 · 0 comments · Fixed by #18
Closed

Each error should be its own subtype #15

edgarsi opened this issue Aug 14, 2022 · 0 comments · Fixed by #18

Comments

@edgarsi
Copy link

edgarsi commented Aug 14, 2022

It is reasonable to rewrite error messages to whatever users find more understandable (e.g. less technical jargon, add use-case recommendations, translate to a different language). Catching DecodingError with a string description is not friendly to that, because descriptions can be revised in future changes. Imo the cleanest solution is to subclass. Maybe something like this:

sealed class DecodingError(params: Params): TomlException() {
    internal data class Params (
        val reason: String,
        val sourceValue: TomlValue,
        val targetType: KType,
        val cause: Throwable? = null
    )
    val reason = params.reason
    val sourceValue = params.sourceValue
    val targetType = params.targetType
    override val cause: Throwable? = params.cause
}

class NoValueForNonNullableParameter internal constructor(params: Params): DecodingError(params)

....
    throw NoValueForNonNullableParameter(DecodingError.Params(
        "no value found for non-nullable parameter '${constructorParameter.name}'",
        tomlMap,
        kType
        ))
valderman added a commit that referenced this issue Sep 19, 2022
Fixes #15.

* Bump dependency versions.

* Split encoder and decoder errors into one type per possible error.

* Split serialization errors into separate types.

* Document new exceptions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant