Exceptions

TranslitError

from translit import TranslitError

Base exception for all translit errors. Inherits from Exception.

Raised when:

  • An invalid normalization form is specified (e.g., form="INVALID")
  • An invalid error mode is specified (e.g., errors="unknown")
  • An invalid platform is specified (e.g., platform="bsd")
  • A regex pattern fails to compile (in slugify(regex_pattern=...))
  • Any other internal error occurs in the Rust layer

Example

from translit import normalize, TranslitError

try:
    normalize("text", form="INVALID")
except TranslitError as e:
    print(f"translit error: {e}")

Catching errors

TranslitError is a standard Python exception. You can catch it specifically or as part of a broader Exception handler:

try:
    result = slugify(text, regex_pattern="[invalid")
except TranslitError:
    # Handle translit-specific errors
    pass
except Exception:
    # Handle any error
    pass

Error messages

Error messages are generated by the Rust layer and describe the specific issue:

Invalid normalization form: INVALID. Expected one of: NFC, NFD, NFKC, NFKD
Invalid error mode: unknown. Expected one of: replace, ignore, preserve
Invalid platform: bsd. Expected one of: universal, posix, windows
Regex compilation error: ...