-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Enhancement] Create bug report functionality #365
Comments
Thanks Greg! For the record:
import inspect
class BugReportError(Exception):
def __init__(self, message):
stack = inspect.stack()
# The caller function is at index 1 (0 is current function - __init__)
_, _, _, function_name, _, _ = stack[1]
BUG_REPORT_URL = "https://github.com/cytomining/pycytominer/issues"
bug_message = (
f"This is likely a bug."
"Please help us improve our software by filing a bug report at "
f"{BUG_REPORT_URL}."
)
full_message = (
f"BugReportError in {function_name}: {message}"
f"\n\n{bug_message}"
)
super().__init__(full_message) import pytest
import inspect
from your_module import BugReportError # Replace 'your_module' with the actual module name
def test_bug_report_error_message():
def dummy_function():
raise BugReportError("Test error message")
with pytest.raises(BugReportError) as exc_info:
dummy_function()
error_message = str(exc_info.value)
assert "dummy_function" in error_message
assert "Test error message" in error_message
assert "https://github.com/cytomining/pycytominer/issues" in error_message
# Run the test with pytest from the command line |
11 tasks
I like the suggestion of using a dedicated error class too. I did some research and that's closer to standard practice. I think it might be good to create an class PycytominerException(Exception):
BUG_REPORT_URL = "https://github.com/cytomining/pycytominer/issues"
EXPERIMENTAL_FEATURE_ADDON = f"""
This error occurred in a new/experimental feature of pycytominer and may be a bug.
Please help us improve our software by filing a bug report at {BUG_REPORT_URL}
"""
def __init__(self, message: str, experimental:bool = False)
message = self.EXPERIMENTAL_FEATURE_ADDON + message if experimental else message
super.__init__(message) This would also address two concerns I had around the previous method.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in #320, @shntnu introduced a function, which @kenibrewer and I recommended be removed from the PR to be added separately later. This issue documents @shntnu 's progress in this effort:
Makes sense, but instead, I'll just copy the code snippet here because I bet you'd want to do this more systematically later
Originally posted by @shntnu in #320 (comment)
The text was updated successfully, but these errors were encountered: