scoop:scoop.idna:0.1.0
src/errors.scoop
Selected production source · src/errors.scoop
1
package scoop.idna3
/**4
* The validation stage or backend failure responsible for an [IdnaException].5
*/6
public enum IdnaFailureKind {7
/**8
* The input fails label structure or UTS #46 validity checks. The backend may9
* not distinguish A-label, contextual, or bidirectional failures.10
*/11
InvalidLabel,12
/**13
* An ASCII encoded label fails validation or round-trip checks.14
*/15
InvalidAlabel,16
/**17
* The label contains a character forbidden by the IDNA profile.18
*/19
Disallowed,20
/**21
* A context-dependent character occurs in an invalid context.22
*/23
Context,24
/**25
* The label violates bidirectional text rules.26
*/27
Bidi,28
/**29
* A label or complete domain exceeds the supported DNS length.30
*/31
NameTooLong,32
/**33
* The native backend could not complete the conversion.34
*/35
Backend }37
/**38
* A domain conversion failure with an operation name and structured failure kind. Optional backend39
* and label information is available when the failing operation can provide it.40
*/41
public class IdnaException public constructor(42
/**43
* The conversion operation that failed.44
*/45
public val operation: String,46
/**47
* The input-validation or backend category of the failure.48
*/49
public val kind: IdnaFailureKind,50
/**51
* The backend error code when one is available.52
*/53
public val code: Int?,54
/**55
* A human-readable explanation of the failure.56
*/57
public val detail: String,58
/**59
* The zero-based index of the failing label when known.60
*/61
public val labelIndex: Long? = None62
) : Exception(Some(operation + ": " + detail))64
internal fun failureKind(code: Int): IdnaFailureKind = when (code) {65
-1004 -> IdnaFailureKind.NameTooLong66
-1003 -> IdnaFailureKind.Disallowed67
-1000, -1001, -1005, -1006 -> IdnaFailureKind.InvalidLabel68
else -> IdnaFailureKind.Backend69
}