Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 21 additions & 5 deletions PyBugReporter/src/BugReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,40 @@ def _handleError(self, e: Exception, repoName: str, *args, **kwargs) -> None:
if self.extraInfo:
description += f"\nExtra Info: {self.kwargs}"

# shortened description for discord if too long (shortens the error text)
start = f"# {title}\n\nType: {excType}\nError text: "
compress = f"{e}\nTraceback: {traceback.format_exc()}"
end = f"\n\nFunction Name: {functionName}\nArguments: {args}\nKeyword Arguments: {kwargs}"
if self.extraInfo:
end += f"\nExtra Info: {self.kwargs}"

staticLength = len(start) + len(end)
if staticLength > 2000:
shortDescription = f"# {title}\n\n" + description[:2000 - len(f"# {title}\n\n") - 3] + "..."
else:
shortDescription = f"{start}{compress[:2000 - staticLength]}{end}"

print(f"SHORT DESCRIPTION with length {len(shortDescription)}:\n{shortDescription}")


# Check if we need to send a bug report
if not self.handlers[repoName].test:
self._sendBugReport(repoName, title, description)
self._sendBugReport(repoName, title, description, shortDescription)

print(title)
print(description)
raise e

def _sendBugReport(self, repoName: str, errorTitle: str, errorMessage: str) -> None:
def _sendBugReport(self, repoName: str, errorTitle: str, errorMessage: str, shortErrorMessage: str) -> None:
"""Sends a bug report to the Github repository.

Args:
errorTitle (str): the title of the error
errorMessage (str): the error message
"""
asyncio.run(self._sendBugReport_async(repoName, errorTitle, errorMessage))
asyncio.run(self._sendBugReport_async(repoName, errorTitle, errorMessage, shortErrorMessage))

async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessage: str) -> None:
async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessage: str, shortErrorMessage: str) -> None:
"""Sends a bug report to the Github repository asynchronously.

Args:
Expand Down Expand Up @@ -197,7 +213,7 @@ async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessag
# Send to Discord if applicable
if self.handlers[repoName].useDiscord:
discordBot = DiscordBot(self.handlers[repoName].botToken, self.handlers[repoName].channelId)
await discordBot.send_message(f"## {repoName}: {errorTitle}\n{errorMessage}", issueExists)
await discordBot.send_message(shortErrorMessage, issueExists)

if (not issueExists):
result = await client.execute_async(query=createIssue, variables=variables, headers=headers)
Expand Down
35 changes: 34 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@

@BugReporter('PyBugReporter', extraInfo=True, env='test')
def test(item, item2=None):
raise Exception("This is a test exception")
raise Exception("""
This is a really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really
really really really really really really really really long test exception
""")

test(None, item2='item2')