<commit_before>package org.http4k.lens

data class LensFailure(val failures: List<Failure>, override val cause: Exception? = null, val target: Any? = null) : Exception(failures.joinToString { it.toString() }, cause) {

    constructor(vararg failures: Failure, cause: Exception? = null, target: Any? = null) : this(failures.asList(), cause, target)

    fun overall(): Failure.Type =
        with(failures.map { it.type }) {
            when {
                contains(Failure.Type.Unsupported) -> Failure.Type.Unsupported
                isEmpty() || contains(Failure.Type.Invalid) -> Failure.Type.Invalid
                else -> Failure.Type.Missing
            }
        }
}

sealed class Failure(val type: Type, open val error: Exception? = null) {
    enum class Type {
        Invalid, Missing, Unsupported
    }

    abstract val meta: Meta
}

data class Missing(override val meta: Meta) : Failure(Type.Missing) {
    override fun toString(): String = "${meta.location} '${meta.name}' is required"
}

data class Invalid(override val meta: Meta, override val error: Exception?) : Failure(Type.Invalid, error) {
    constructor(meta: Meta) : this(meta, null)
    override fun toString(): String = "${meta.location} '${meta.name}' must be ${meta.paramMeta.value}"
}

data class Unsupported(override val meta: Meta) : Failure(Type.Unsupported) {
    override fun toString(): String = "${meta.location} '${meta.name}' is not acceptable"
}<commit_msg>tweak to method ref<commit_after>package org.http4k.lens

data class LensFailure(val failures: List<Failure>, override val cause: Exception? = null, val target: Any? = null) : Exception(failures.joinToString { it.toString() }, cause) {

    constructor(vararg failures: Failure, cause: Exception? = null, target: Any? = null) : this(failures.asList(), cause, target)

    fun overall(): Failure.Type = with(failures.map(Failure::type)) {
        when {
            contains(Failure.Type.Unsupported) -> Failure.Type.Unsupported
            isEmpty() || contains(Failure.Type.Invalid) -> Failure.Type.Invalid
            else -> Failure.Type.Missing
        }
    }
}

sealed class Failure(val type: Type, open val error: Exception? = null) {
    enum class Type {
        Invalid, Missing, Unsupported
    }

    abstract val meta: Meta
}

data class Missing(override val meta: Meta) : Failure(Type.Missing) {
    override fun toString(): String = "${meta.location} '${meta.name}' is required"
}

data class Invalid(override val meta: Meta, override val error: Exception?) : Failure(Type.Invalid, error) {
    constructor(meta: Meta) : this(meta, null)

    override fun toString(): String = "${meta.location} '${meta.name}' must be ${meta.paramMeta.value}"
}

data class Unsupported(override val meta: Meta) : Failure(Type.Unsupported) {
    override fun toString(): String = "${meta.location} '${meta.name}' is not acceptable"
}
{'fraction_non_alphanumeric': 0.1342817487855656, 'fraction_numerical': 0.0006939625260235947, 'mean_word_length': 3.583465818759936, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3831976', 'n_tokens_mistral': 831, 'n_tokens_neox': 805, 'n_words': 242}