geowatch.utils.util_exception module

TODO: port to kwutil

geowatch.utils.util_exception.add_exception_note(ex, note, force_legacy=False)[source]

Support for PEP 678 in Python < 3.11

If PEP 678 is available, use it, otherwise create a new exeception based on the old one with an updated note.

Parameters:
  • ex (BaseException) – the exception to modify

  • note (str) – extra unstructured information to add

  • force_legacy (bool) – for testing

Returns:

modified exception

Return type:

BaseException

Example

>>> from geowatch.utils.util_exception import add_exception_note
>>> ex = Exception('foo')
>>> new_ex = add_exception_note(ex, 'hello world', force_legacy=False)
>>> print(new_ex)
>>> new_ex = add_exception_note(ex, 'hello world', force_legacy=True)
>>> print(new_ex)