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 function to store an error in a txt file #30

Merged
merged 1 commit into from
May 10, 2024
Merged
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
21 changes: 21 additions & 0 deletions gluestick/etl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,3 +651,24 @@ def localize_datetime(df, column_name):
df[column_name] = df[column_name].dt.tz_convert('UTC')

return df[column_name]

def exception(exception, root_dir, error_message=None):
"""
Stores an exception and a message into a file errors.txt,
then the executor reads the error from the txt file to showcase the right error.
It should be used instead of raise Exception.
Parameters:
-----------
exception : the exception caught in a try except code.
root_dir : str
The path of the roo_dir to store errors.txt
error_message: str
Additional message or data to make the error clearer.
"""
if error_message:
error = f"ERROR: {error_message}. Cause: {exception}"
else:
error = f"ERROR: {exception}"
with open(f"{root_dir}/errors.txt", "w") as outfile:
outfile.write(error)
raise Exception(error)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="gluestick",
version="2.1.14",
version="2.1.15",
description="ETL utility functions built on Pandas",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
Loading