Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: Simplified the error messages and added a bit more info to one of them #6

Merged
merged 7 commits into from
Dec 21, 2023
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
6 changes: 6 additions & 0 deletions memphis/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dataclasses import dataclass

@dataclass
class Errors:
invalid_types = "The returned processed_message or processed_headers were not in the right format. processed_message must be bytes and processed_headers, dict"
conversion_error = "Returned message types from user function are not able to be converted into JSON:"
13 changes: 7 additions & 6 deletions memphis/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import base64
import asyncio
from errors import Errors

def create_function(
event,
Expand Down Expand Up @@ -105,12 +106,12 @@ async def handler(event):
})
elif processed_message is None and processed_headers is None: # filter out empty messages
continue
elif processed_message is None or processed_headers is None:
err_msg = f"processed_messages is of type {type(processed_message)} and processed_headers is {type(processed_headers)}. Either both of these should be None or neither"
raise Exception(err_msg)
else:
err_msg = "The returned processed_message or processed_headers were not in the right format. processed_message must be bytes and processed_headers, dict"
raise Exception(err_msg)
err_msg = f"""Either processed_message or processed_headers were of the wrong type.
processed_message should be of type bytes and processed_headers should be of type Dict. Ensure these types are correct.
processed_message is of type {type(processed_message)} and processed_headers if of type {type(processed_headers)}.
"""
raise Exception(Errors.invalid_types)
except Exception as e:
processed_events["failed_messages"].append({
"headers": message["headers"],
Expand All @@ -121,6 +122,6 @@ async def handler(event):
try:
return json.dumps(processed_events, cls=EncodeBase64).encode('utf-8')
except Exception as e:
return f"Returned message types from user function are not able to be converted into JSON: {e}"
return f"Returned message types from user function are not able to be converted into JSON: {str(e)}"

return asyncio.run(handler(event))