mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-23 15:38:14 +01:00
20 lines
452 B
Python
20 lines
452 B
Python
|
import contextlib
|
||
|
from typing import Tuple
|
||
|
|
||
|
|
||
|
@contextlib.contextmanager
|
||
|
def rewrite_exception(old_name: str, new_name: str):
|
||
|
"""
|
||
|
Rewrite the message of an exception.
|
||
|
"""
|
||
|
try:
|
||
|
yield
|
||
|
except Exception as err:
|
||
|
msg = err.args[0]
|
||
|
msg = msg.replace(old_name, new_name)
|
||
|
args: Tuple[str, ...] = (msg,)
|
||
|
if len(err.args) > 1:
|
||
|
args = args + err.args[1:]
|
||
|
err.args = args
|
||
|
raise
|