Skip to main content

N2WError

Enum N2WError 

Source
pub enum N2WError {
    Overflow(String),
    Type(String),
    NotImplemented(String),
    Fallback(String),
    ZeroDivision(String),
    Index(String),
    Key(String),
    Value(String),
    Attribute(String),
    Assertion(String),
    ReturnsNone,
    Custom {
        module: &'static str,
        class: &'static str,
        msg: String,
    },
}
Expand description

Errors mirroring the exception types the Python original raises.

Index, Key and Value exist because several language modules crash on edge inputs rather than raising deliberately — e.g. lang_PL’s to_ordinal(0) pops its last fragment and then indexes an empty list (IndexError), to_ordinal(-1) feeds “-” to int() (ValueError), and to_ordinal(10**12) misses prefixes_ordinal[4] (KeyError).

Those are Python bugs, but they are observable behaviour that callers may catch, so parity requires reproducing the exception type. Do not “improve” them into a tidy TypeError.

Variants§

§

Overflow(String)

§

Type(String)

§

NotImplemented(String)

Python raised NotImplementedError as a DELIBERATE result — the same exception the original produces, so it must propagate to the caller. to_ordinal(>100) in Welsh, an unknown Japanese counter, and the abstract pluralize all land here. Distinct from Fallback.

§

Fallback(String)

Not a Python exception: the Rust core declines this specific call and the binding re-runs the ORIGINAL Python converter, which owns it (an unported kwarg whose Python path raises the real TypeError; an Inf/NaN string a language handles in Python; a sentence sub-case). Kept separate from NotImplemented so a genuine NotImplementedError raise is served natively instead of being swallowed by the shim’s fallback catch.

§

ZeroDivision(String)

§

Index(String)

Python raised IndexError (usually an out-of-range list access).

§

Key(String)

Python raised KeyError (usually a missing dict entry).

§

Value(String)

Python raised ValueError (usually int()/str parsing of a bad token).

§

Attribute(String)

Python raised AttributeError. Usually the converter simply does not define the method or attribute at all — Num2Word_RM has no to_year/to_ordinal_num, and Num2Word_IT has no errmsg_negord — so the crash happens on attribute lookup, before any conversion.

§

Assertion(String)

Python raised AssertionError. lang_AR asserts its bounds instead of raising deliberately, so to_ordinal(>=10**51) and to_cardinal(-(10**51)) surface as AssertionError, not OverflowError.

§

ReturnsNone

Not an error: Python’s function fell off the end and returned None.

lang_VI does this past 10^75 — no raise, no string, just an implicit None that propagates to the caller. None is a success value, so the binding turns this sentinel into Python None rather than an exception. Modelled as an Err variant purely to avoid rewriting Result<String> to Result<Option<String>> across 154 language files.

§

Custom

Python raised an exception class defined in a language module rather than a builtin: (module_path, class_name, message).

lang_BN.py is the only case in the library — it defines NumberTooLargeError(Exception) and raises it past MAX_NUMBER (~10^306) instead of OverflowError. The binding imports the class and raises the real thing, so except NumberTooLargeError keeps working.

Fields

§module: &'static str
§class: &'static str

Trait Implementations§

Source§

impl Debug for N2WError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.