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

Improve error message if handle() method not implemented in Command. #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brettp
Copy link
Contributor

@brettp brettp commented May 12, 2024

Small quality of life improvement that prevents an unhelpful error if you have a typo in the handle() method (and spent longer than you should have wondering what wasn't working).

Was:
ERROR:root:[TestCommand] Error:

Now:
ERROR:root:[TestCommand] Error: handle() method not implemented

@brettp
Copy link
Contributor Author

brettp commented May 12, 2024

I updated this to improve the error logging for the other case also by adding the exception class.

Was:

ERROR:root:[TestCommand] Error: 'res'

Now:

ERROR:root:[TestCommand] <class 'KeyError'> Error: 'res'

except Exception as e:
logging.error(f"[{command.__class__.__name__}] Error: {e}")
logging.error(f"[{command.__class__.__name__}] {e.__class__} Error: {e}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the message nicer, can we use e.__class__.__name__ instead? What about this format:

f"[{command.__class__.__name__}] {e.__class__.__name__}: {e}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants