Skip to content

Commit 72310ed

Browse files
committed
added compressable middle part of the error message so that we can have a short description for discord
1 parent 2931b6a commit 72310ed

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

PyBugReporter/src/BugReporter.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,40 @@ def _handleError(self, e: Exception, repoName: str, *args, **kwargs) -> None:
130130
if self.extraInfo:
131131
description += f"\nExtra Info: {self.kwargs}"
132132

133+
# shortened description for discord if too long (shortens the error text)
134+
start = f"# {title}\n\nType: {excType}\nError text: "
135+
compress = f"{e}\nTraceback: {traceback.format_exc()}"
136+
end = f"\n\nFunction Name: {functionName}\nArguments: {args}\nKeyword Arguments: {kwargs}"
137+
if self.extraInfo:
138+
end += f"\nExtra Info: {self.kwargs}"
139+
140+
staticLength = len(start) + len(end)
141+
if staticLength > 2000:
142+
shortDescription = f"# {title}\n\n" + description[:2000 - len(f"# {title}\n\n") - 3] + "..."
143+
else:
144+
shortDescription = f"{start}{compress[:2000 - staticLength]}{end}"
145+
146+
print(f"SHORT DESCRIPTION with length {len(shortDescription)}:\n{shortDescription}")
147+
148+
133149
# Check if we need to send a bug report
134150
if not self.handlers[repoName].test:
135-
self._sendBugReport(repoName, title, description)
151+
self._sendBugReport(repoName, title, description, shortDescription)
136152

137153
print(title)
138154
print(description)
139155
raise e
140156

141-
def _sendBugReport(self, repoName: str, errorTitle: str, errorMessage: str) -> None:
157+
def _sendBugReport(self, repoName: str, errorTitle: str, errorMessage: str, shortErrorMessage: str) -> None:
142158
"""Sends a bug report to the Github repository.
143159
144160
Args:
145161
errorTitle (str): the title of the error
146162
errorMessage (str): the error message
147163
"""
148-
asyncio.run(self._sendBugReport_async(repoName, errorTitle, errorMessage))
164+
asyncio.run(self._sendBugReport_async(repoName, errorTitle, errorMessage, shortErrorMessage))
149165

150-
async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessage: str) -> None:
166+
async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessage: str, shortErrorMessage: str) -> None:
151167
"""Sends a bug report to the Github repository asynchronously.
152168
153169
Args:
@@ -197,7 +213,7 @@ async def _sendBugReport_async(self, repoName: str, errorTitle: str, errorMessag
197213
# Send to Discord if applicable
198214
if self.handlers[repoName].useDiscord:
199215
discordBot = DiscordBot(self.handlers[repoName].botToken, self.handlers[repoName].channelId)
200-
await discordBot.send_message(f"## {repoName}: {errorTitle}\n{errorMessage}", issueExists)
216+
await discordBot.send_message(shortErrorMessage, issueExists)
201217

202218
if (not issueExists):
203219
result = await client.execute_async(query=createIssue, variables=variables, headers=headers)

test.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@
1818

1919
@BugReporter('PyBugReporter', extraInfo=True, env='test')
2020
def test(item, item2=None):
21-
raise Exception("This is a test exception")
21+
raise Exception("""
22+
This is a really really really really really really really really
23+
really really really really really really really really
24+
really really really really really really really really
25+
really really really really really really really really
26+
really really really really really really really really
27+
really really really really really really really really
28+
really really really really really really really really
29+
really really really really really really really really
30+
really really really really really really really really
31+
really really really really really really really really
32+
really really really really really really really really
33+
really really really really really really really really
34+
really really really really really really really really
35+
really really really really really really really really
36+
really really really really really really really really
37+
really really really really really really really really
38+
really really really really really really really really
39+
really really really really really really really really
40+
really really really really really really really really
41+
really really really really really really really really
42+
really really really really really really really really
43+
really really really really really really really really
44+
really really really really really really really really
45+
really really really really really really really really
46+
really really really really really really really really
47+
really really really really really really really really
48+
really really really really really really really really
49+
really really really really really really really really
50+
really really really really really really really really
51+
really really really really really really really really
52+
really really really really really really really really
53+
really really really really really really really really long test exception
54+
""")
2255

2356
test(None, item2='item2')

0 commit comments

Comments
 (0)