remap_wit_errors
Raise more idiomatic exceptions from a function that returns a WIT result.
A results error case is always wrapped in a generic Err exception by
componentize-py. Convert that to a more descriptive exception that can be
selectively caught.
Goals: Be idiomatic. Be reasonably efficient. Be readable as documentation. In that order.
Parameters
- idiomatic_exceptions: Mapping[Any, type[FastlyError]] | Noneoptional =
None A map of the types of WIT-level
Err.values to more informative exception classes. These classes receive theErr.valueas a constructor argument. If the value's type is not found in the map, wrap it in anUnexpectedFastlyError.Enum members may also be used as mapping keys. Exceptions raised based on these receive no constructor arguments, since the values of enum members are generated and meaningless.
Returns