PyBugReporter 1.0.12__tar.gz → 1.0.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyBugReporter
3
- Version: 1.0.12
3
+ Version: 1.0.15
4
4
  Summary: A python library for catching thrown exceptions and automatically creating issues on a GitHub repo.
5
5
  Home-page: https://github.com/byuawsfhtl/PyBugReporter.git
6
6
  Author: Record Linking Lab
@@ -0,0 +1 @@
1
+ __version__ = '1.0.15'
@@ -1,4 +1,5 @@
1
1
  import asyncio
2
+ import inspect
2
3
  import sys
3
4
  import traceback
4
5
  from functools import wraps
@@ -93,20 +94,38 @@ class BugReporter:
93
94
  Args:
94
95
  func (callable): the function to be decorated
95
96
  """
96
- @wraps(func)
97
- def wrapper(*args, **kwargs) -> None:
98
- """Wrapper function that catches exceptions and sends a bug report to the github repository.
99
-
100
- Args:
101
- *args: the arguments for the function
102
- **kwargs: the keyword arguments for the function
103
- """
104
- repoName = self.repoName
105
- try:
106
- return func(*args, **kwargs)
107
- except Exception as e:
108
- self._handleError(e, repoName, *args, **kwargs)
109
- return wrapper
97
+ if inspect.iscoroutinefunction(func):
98
+ @wraps(func)
99
+ async def wrapper_async(*args, **kwargs) -> None:
100
+ """Wrapper function that catches exceptions and sends a bug report to the github repository.
101
+ Works for async functions.
102
+
103
+ Args:
104
+ *args: the arguments for the function
105
+ **kwargs: the keyword arguments for the function
106
+ """
107
+ repoName = self.repoName
108
+ try:
109
+ return func(*args, **kwargs)
110
+ except Exception as e:
111
+ await self._handleError_async(e, repoName, *args, **kwargs)
112
+ return wrapper_async
113
+ else:
114
+ @wraps(func)
115
+ def wrapper(*args, **kwargs) -> None:
116
+ """Wrapper function that catches exceptions and sends a bug report to the github repository.
117
+ Works for synchronous functions.
118
+
119
+ Args:
120
+ *args: the arguments for the function
121
+ **kwargs: the keyword arguments for the function
122
+ """
123
+ repoName = self.repoName
124
+ try:
125
+ return func(*args, **kwargs)
126
+ except Exception as e:
127
+ self._handleError(e, repoName, *args, **kwargs)
128
+ return wrapper
110
129
 
111
130
  def _handleError(self, e: Exception, repoName: str, *args, **kwargs) -> None:
112
131
  """Handles error by creating a bug report.
@@ -117,6 +136,46 @@ class BugReporter:
117
136
  Raises:
118
137
  e: the exception that was raised
119
138
  """
139
+ title, description, shortDescription = self._prepare_bug_report(e, repoName, args, kwargs)
140
+
141
+ # Check if we need to send a bug report
142
+ if not self.handlers[repoName].test:
143
+ self._sendBugReport(repoName, title, description, shortDescription)
144
+
145
+ print(title)
146
+ print(description)
147
+ raise e
148
+
149
+ async def _handleError_async(self, e: Exception, repoName: str, *args, **kwargs) -> None:
150
+ """Handles error by creating a bug report asynchronously.
151
+
152
+ Args:
153
+ e (Exception): the exception that was raised
154
+
155
+ Raises:
156
+ e: the exception that was raised
157
+ """
158
+ title, description, shortDescription = self._prepare_bug_report(e, repoName, args, kwargs)
159
+
160
+ # Check if we need to send a bug report
161
+ if not self.handlers[repoName].test:
162
+ await self._sendBugReport_async(repoName, title, description, shortDescription)
163
+
164
+ print(title)
165
+ print(description)
166
+ raise e
167
+
168
+
169
+ def _prepare_bug_report(self, e: Exception, repoName: str, *args, **kwargs) -> tuple[str,str,str]:
170
+ """Prepares all information needed to send the bug report.
171
+
172
+ Args:
173
+ e (Exception): the exception that was raised
174
+
175
+ Returns:
176
+ tuple[str,str,str]: The title, description, and short description of the error for the report.
177
+
178
+ """
120
179
  excType = type(e).__name__
121
180
  tb = traceback.extract_tb(sys.exc_info()[2])
122
181
  functionName = tb[-1][2]
@@ -144,15 +203,7 @@ class BugReporter:
144
203
  shortDescription = f"{start}{compress[:2000 - staticLength]}{end}"
145
204
 
146
205
  print(f"SHORT DESCRIPTION with length {len(shortDescription)}:\n{shortDescription}")
147
-
148
-
149
- # Check if we need to send a bug report
150
- if not self.handlers[repoName].test:
151
- self._sendBugReport(repoName, title, description, shortDescription)
152
-
153
- print(title)
154
- print(description)
155
- raise e
206
+ return title,description,shortDescription
156
207
 
157
208
  def _sendBugReport(self, repoName: str, errorTitle: str, errorMessage: str, shortErrorMessage: str) -> None:
158
209
  """Sends a bug report to the Github repository.
@@ -213,7 +264,7 @@ class BugReporter:
213
264
  # Send to Discord if applicable
214
265
  if self.handlers[repoName].useDiscord:
215
266
  discordBot = DiscordBot(self.handlers[repoName].botToken, self.handlers[repoName].channelId)
216
- await discordBot.send_message(shortErrorMessage, issueExists)
267
+ await discordBot.send_message(shortErrorMessage, issueExists, errorTitle)
217
268
 
218
269
  if (not issueExists):
219
270
  result = await client.execute_async(query=createIssue, variables=variables, headers=headers)
@@ -430,7 +481,7 @@ class BugReporter:
430
481
  # Send to Discord if applicable
431
482
  if cls.handlers[repoName].useDiscord:
432
483
  discordBot = DiscordBot(cls.handlers[repoName].botToken, cls.handlers[repoName].channelId)
433
- await discordBot.send_message(f"## {repoName}: {errorTitle}\n{errorMessage}", issueExists)
484
+ await discordBot.send_message(f"## {repoName}: {errorTitle}\n{errorMessage}", issueExists, errorTitle)
434
485
 
435
486
  if (issueExists == False):
436
487
  result = await client.execute_async(query=createIssue, variables=variables, headers=headers)
@@ -27,6 +27,7 @@ class DiscordBot(discord.Client):
27
27
  self.channelId = int(channelId)
28
28
  self._message = None
29
29
  self._alreadySent = False
30
+ self._title = None
30
31
  self._doneFuture = None
31
32
 
32
33
  intents = discord.Intents(emojis = True,
@@ -36,16 +37,18 @@ class DiscordBot(discord.Client):
36
37
  guilds = True)
37
38
  super().__init__(intents=intents)
38
39
 
39
- async def send_message(self, message, alreadySent = False):
40
+ async def send_message(self, message, alreadySent = False, title = None):
40
41
  """
41
42
  Sends a message to the specified channel by setting the variables and starting the bot, then turning it off when finished.
42
43
 
43
44
  Args:
44
45
  message (str): The message to send.
45
46
  alreadySent (bool): Whether the message has already been sent.
47
+ title (str): The stable error title used to find the original message when reacting.
46
48
  """
47
49
  self._message = message
48
50
  self._alreadySent = alreadySent
51
+ self._title = title
49
52
  self._doneFuture = asyncio.get_running_loop().create_future()
50
53
  print("Starting bot...")
51
54
  # Start the bot as a background task
@@ -64,7 +67,7 @@ class DiscordBot(discord.Client):
64
67
  print(f"Sent message to channel {self.channelId}")
65
68
  elif channel and self._alreadySent:
66
69
  async for message in channel.history(limit=HISTORY_LIMIT):
67
- if message.content == self._message:
70
+ if self._title and self._title in message.content:
68
71
  await message.add_reaction(EMOJI)
69
72
  break
70
73
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyBugReporter
3
- Version: 1.0.12
3
+ Version: 1.0.15
4
4
  Summary: A python library for catching thrown exceptions and automatically creating issues on a GitHub repo.
5
5
  Home-page: https://github.com/byuawsfhtl/PyBugReporter.git
6
6
  Author: Record Linking Lab
@@ -1 +0,0 @@
1
- __version__ = '1.0.12'
File without changes
File without changes
File without changes
File without changes