Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper to enhance info on failed facade creation #145

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Features

* Improve reading error message `#134 <https://github.com/oemof/oemof-tabular/pull/134>`_
* Remove facade relicts `#135 <https://github.com/oemof/oemof-tabular/pull/135>`_
* Reading error enhancer `#145 <https://github.com/oemof/oemof-tabular/pull/145>`_
* Add dev install version `#147 <https://github.com/oemof/oemof-tabular/pull/147>`_


Fixes

* Remove specific dirs from flake8 & isort `#136 <https://github.com/oemof/oemof-tabular/pull/136>`_
Expand Down
23 changes: 23 additions & 0 deletions src/oemof/tabular/datapackage/reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@
FLOW_TYPE = object()


def error_enhancer(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
# Add additional information to the error message
facade_type = args[0].get("type", None)
facade_name = args[0].get("name", None)
if facade_type is not None and facade_name is not None:
additional_info = (
f"\nFailed creating '{facade_type}' with "
f"name '{facade_name}'."
)
new_error_message = f"{str(e)} - {additional_info}"
else:
new_error_message = str(e)
# Raise the enhanced error
raise type(e)(new_error_message).with_traceback(e.__traceback__)

return wrapper


def sequences(r, timeindices=None):
"""Parses the resource `r` as a sequence."""
result = {
Expand All @@ -44,6 +66,7 @@ def sequences(r, timeindices=None):
return result


@error_enhancer
def read_facade(
facade,
facades,
Expand Down
Loading