Skip to main content

ens_normalize_rs/
error.rs

1use crate::CodePoint;
2
3/// Errors that can occur during processing of an ENS name.
4#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
5pub enum ProcessError {
6    #[error("contains visually confusing characters from multiple scripts: {0}")]
7    Confused(String),
8    #[error("contains visually confusing characters from {group1} and {group2} scripts")]
9    ConfusedGroups { group1: String, group2: String },
10    #[error("invalid character ('{sequence}') at position {index}: {inner}")]
11    CurrableError {
12        inner: CurrableError,
13        index: usize,
14        sequence: String,
15        maybe_suggest: Option<String>,
16    },
17    #[error("disallowed sequence: {0}")]
18    DisallowedSequence(#[from] DisallowedSequence),
19}
20
21/// Errors that can be cured by the normalizer.
22#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
23pub enum CurrableError {
24    #[error("underscore in middle")]
25    UnderscoreInMiddle,
26    #[error("hyphen at second and third position")]
27    HyphenAtSecondAndThird,
28    #[error("combining mark in disallowed position at the start of the label")]
29    CmStart,
30    #[error("combining mark in disallowed position after an emoji")]
31    CmAfterEmoji,
32    #[error("fenced character at the start of a label")]
33    FencedLeading,
34    #[error("fenced character at the end of a label")]
35    FencedTrailing,
36    #[error("consecutive sequence of fenced characters")]
37    FencedConsecutive,
38}
39
40/// Errors regarding disallowed sequences.
41#[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)]
42pub enum DisallowedSequence {
43    #[error("disallowed character: {0}")]
44    Invalid(String),
45    #[error("invisible character: {0}")]
46    InvisibleCharacter(CodePoint),
47    #[error("empty label")]
48    EmptyLabel,
49    #[error("nsm too many")]
50    NsmTooMany,
51    #[error("nsm repeated")]
52    NsmRepeated,
53}