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.