Skip to content

Commit 77a3138

Browse files
committed
Update error gist
1 parent 8e86006 commit 77a3138

8 files changed

Lines changed: 57 additions & 41 deletions

File tree

modules/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import re
2626

2727
from modules.structs import ContextLimiter, CounterContext, Game, MsgBox, OldGame, Os, SearchResult, Status
28-
from modules import globals, async_thread, callbacks, colors, db, icons, msgbox, parser, utils
28+
from modules import globals, async_thread, callbacks, colors, db, error, icons, msgbox, parser, utils
2929

3030
session: aiohttp.ClientSession = None
3131
full_interval = int(dt.timedelta(days=7).total_seconds())
@@ -145,7 +145,7 @@ async def login():
145145
new_cookies = json.loads(data[0])
146146
await asyncio.shield(db.update_cookies(new_cookies))
147147
except Exception:
148-
raise msgbox.Exc("Login window failure", f"Something went wrong with the login window subprocess:\n{utils.get_error()}\n\nThe \"log.txt\" file might contain more information.\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=utils.get_traceback())
148+
raise msgbox.Exc("Login window failure", f"Something went wrong with the login window subprocess:\n{error.text()}\n\nThe \"log.txt\" file might contain more information.\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=error.traceback())
149149

150150

151151
async def assert_login():
@@ -470,7 +470,7 @@ async def check_notifs(login=False):
470470
except Exception:
471471
async with aiofiles.open(globals.self_path / "notifs_broken.bin", "wb") as f:
472472
await f.write(res)
473-
raise msgbox.Exc("Notifs check error", f"Something went wrong checking your unread notifications:\n{utils.get_error()}\n\nThe response body has been saved to:\n{globals.self_path}{os.sep}notifs_broken.bin\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=utils.get_traceback())
473+
raise msgbox.Exc("Notifs check error", f"Something went wrong checking your unread notifications:\n{error.text()}\n\nThe response body has been saved to:\n{globals.self_path}{os.sep}notifs_broken.bin\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=error.traceback())
474474
if alerts != 0 and inbox != 0:
475475
msg = f"You have {alerts + inbox} unread notifications.\n({alerts} alert{'s' if alerts > 1 else ''} and {inbox} conversation{'s' if inbox > 1 else ''})"
476476
elif alerts != 0 and inbox == 0:
@@ -539,7 +539,7 @@ async def check_updates():
539539
except Exception:
540540
async with aiofiles.open(globals.self_path / "update_broken.bin", "wb") as f:
541541
await f.write(res)
542-
raise msgbox.Exc("Update check error", f"Something went wrong checking for F95Checker updates:\n{utils.get_error()}\n\nThe response body has been saved to:\n{globals.self_path}{os.sep}update_broken.bin\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=utils.get_traceback())
542+
raise msgbox.Exc("Update check error", f"Something went wrong checking for F95Checker updates:\n{error.text()}\n\nThe response body has been saved to:\n{globals.self_path}{os.sep}update_broken.bin\nPlease submit a bug report on F95Zone or GitHub including this file.", MsgBox.error, more=error.traceback())
543543
async def update_callback():
544544
progress = 0.0
545545
total = float(asset_size)

modules/callbacks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import os
1111

1212
from modules.structs import Game, MsgBox, Os, SearchResult, ThreadMatch
13-
from modules import globals, api, async_thread, db, filepicker, icons, msgbox, utils
13+
from modules import globals, api, async_thread, db, error, filepicker, icons, msgbox, utils
1414

1515

1616
def update_start_with_system(toggle: bool):
@@ -48,7 +48,7 @@ def update_start_with_system(toggle: bool):
4848
globals.autostart.unlink()
4949
globals.start_with_system = toggle
5050
except Exception:
51-
utils.push_popup(msgbox.msgbox, "Start with system error", f"Something went wrong changing the start with system setting:\n{utils.get_error()}", MsgBox.error, more=utils.get_traceback())
51+
utils.push_popup(msgbox.msgbox, "Start with system error", f"Something went wrong changing the start with system setting:\n{error.text()}", MsgBox.error, more=error.traceback())
5252

5353

5454
async def _launch_exe(path: str):
@@ -121,7 +121,7 @@ def select_callback(selected):
121121
}
122122
utils.push_popup(msgbox.msgbox, "File not found", "The selected executable could not be found.\n\nDo you want to select another one?", MsgBox.warn, buttons)
123123
except Exception:
124-
utils.push_popup(msgbox.msgbox, "Game launch error", f"Something went wrong launching {executable}:\n{utils.get_error()}", MsgBox.error, more=utils.get_traceback())
124+
utils.push_popup(msgbox.msgbox, "Game launch error", f"Something went wrong launching {executable}:\n{error.text()}", MsgBox.error, more=error.traceback())
125125

126126

127127
def launch_game(game: Game, executable: str = None):
@@ -189,7 +189,7 @@ def select_callback(selected):
189189
}
190190
utils.push_popup(msgbox.msgbox, "Folder not found", "The parent folder for the game executable could not be found.\n\nDo you want to select another executable?", MsgBox.warn, buttons)
191191
except Exception:
192-
utils.push_popup(msgbox.msgbox, "Open folder error", f"Something went wrong opening the folder for {executable}:\n{utils.get_error()}", MsgBox.error, more=utils.get_traceback())
192+
utils.push_popup(msgbox.msgbox, "Open folder error", f"Something went wrong opening the folder for {executable}:\n{error.text()}", MsgBox.error, more=error.traceback())
193193

194194

195195
def open_game_folder(game: Game, executable: str = None):
@@ -246,7 +246,7 @@ async def _open_webpage(url: str):
246246
stderr=subprocess.DEVNULL
247247
)
248248
except Exception:
249-
utils.push_popup(msgbox.msgbox, "Open webpage error", f"Something went wrong opening {name}:\n{utils.get_error()}", MsgBox.error, more=utils.get_traceback())
249+
utils.push_popup(msgbox.msgbox, "Open webpage error", f"Something went wrong opening {name}:\n{error.text()}", MsgBox.error, more=error.traceback())
250250
if globals.settings.browser_html:
251251
async def _fetch_open_page():
252252
html = await api.download_webpage(url)

modules/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212

1313
from modules.structs import Browser, DefaultStyle, DisplayMode, Game, MsgBox, SearchResult, Settings, Status, ThreadMatch, Timestamp, Type
14-
from modules import globals, async_thread, colors, msgbox, utils
14+
from modules import globals, async_thread, colors, error, msgbox, utils
1515

1616
connection: aiosqlite.Connection = None
1717

@@ -570,4 +570,4 @@ async def migrate_legacy(config: str | pathlib.Path | dict):
570570

571571
await save()
572572
except Exception:
573-
utils.push_popup(msgbox.msgbox, "Config migration error", f"Something went wrong transferring data from the previous version:\n{utils.get_error()}", MsgBox.error, more=utils.get_traceback())
573+
utils.push_popup(msgbox.msgbox, "Config migration error", f"Something went wrong transferring data from the previous version:\n{error.text()}", MsgBox.error, more=error.traceback())

modules/error.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# https://gist.github.com/Willy-JL/f733c960c6b0d2284bcbee0316f88878
2+
import traceback as _traceback
3+
import sys
4+
5+
6+
def traceback(exc: Exception = None):
7+
# Full error traceback with line numbers and previews
8+
if exc:
9+
exc_info = type(exc), exc, exc.__traceback__
10+
else:
11+
exc_info = sys.exc_info()
12+
tb_lines = _traceback.format_exception(*exc_info)
13+
tb = "".join(tb_lines)
14+
return tb
15+
16+
17+
def text(exc: Exception = None):
18+
# Short error text like "ExcName: exception text"
19+
exc = exc or sys.exc_info()[1]
20+
return f"{type(exc).__name__}: {str(exc) or 'No further details'}"
21+
22+
23+
# Example usage
24+
if __name__ == "__main__":
25+
import error # This script is designed as a module you import
26+
27+
try:
28+
0/0
29+
except Exception as exc:
30+
# can be used with no arguments inside except blocks
31+
print(error.text())
32+
print(error.traceback())
33+
# or if you have the exception object you can pass that
34+
print(error.text(exc))
35+
print(error.traceback(exc))

modules/gui.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import sys
1919

2020
from modules.structs import Browser, DefaultStyle, DisplayMode, ExeState, Filter, FilterMode, Game, MsgBox, Os, SortSpec, Status, Tag, TrayMsg, Type
21-
from modules import globals, api, async_thread, callbacks, colors, db, filepicker, icons, imagehelper, login, msgbox, ratingwidget, rpc_thread, utils
21+
from modules import globals, api, async_thread, callbacks, colors, db, error, filepicker, icons, imagehelper, login, msgbox, ratingwidget, rpc_thread, utils
2222

2323
imgui.io = None
2424
imgui.style = None
@@ -316,8 +316,8 @@ def __init__(self):
316316
# Show errors in threads
317317
def syncexcepthook(args: threading.ExceptHookArgs):
318318
if args.exc_type is not msgbox.Exc:
319-
err = utils.get_error(args.exc_value)
320-
tb = utils.get_traceback(args.exc_type, args.exc_value, args.exc_traceback)
319+
err = error.text(args.exc_value)
320+
tb = error.traceback(args.exc_type, args.exc_value, args.exc_traceback)
321321
utils.push_popup(msgbox.msgbox, "Oops!", f"Something went wrong in a parallel task of a separate thread:\n{err}", MsgBox.error, more=tb)
322322
threading.excepthook = syncexcepthook
323323
def asyncexcepthook(future: asyncio.Future):
@@ -327,8 +327,8 @@ def asyncexcepthook(future: asyncio.Future):
327327
return
328328
if not exc or type(exc) is msgbox.Exc:
329329
return
330-
err = utils.get_error(exc)
331-
tb = utils.get_traceback(exc)
330+
err = error.text(exc)
331+
tb = error.traceback(exc)
332332
if isinstance(exc, asyncio.TimeoutError) or isinstance(exc, aiohttp.ClientError):
333333
utils.push_popup(msgbox.msgbox, "Connection error", f"A connection request to F95Zone has failed:\n{err}\n\nPossible causes include:\n - You are refreshing with too many workers, try lowering them in settings\n - Your timeout value is too low, try increasing it in settings\n - F95Zone is experiencing difficulties, try waiting a bit and retrying\n - F95Zone is blocked in your country, network, antivirus or firewall, try a VPN\n - Your retries value is too low, try increasing it in settings (last resort!)", MsgBox.warn, more=tb)
334334
return

modules/parser.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import multiprocessing
22
import datetime as dt
3-
import traceback
43
import functools
5-
import builtins
64
import bs4
7-
import sys
85
import re
96
import os
107

118
from modules.structs import MsgBox, Status, Tag, Type
9+
from modules import error
1210

1311
html = functools.partial(bs4.BeautifulSoup, features="lxml")
1412
_html = html
@@ -211,14 +209,12 @@ def get_long_game_attr(*names: list[str]):
211209
else:
212210
image_url = "-"
213211

214-
except Exception as exc:
215-
err = f"{builtins.type(exc).__name__}: {str(exc) or 'No further details'}"
216-
tb = "".join(traceback.format_exception(*sys.exc_info()))
212+
except Exception:
217213
e = ParserException(
218214
title="Thread parsing error",
219-
msg=f"Something went wrong while parsing thread {game_id}:\n{err}",
215+
msg=f"Something went wrong while parsing thread {game_id}:\n{error.text()}",
220216
type=MsgBox.error,
221-
more=tb
217+
more=error.traceback()
222218
)
223219
if pipe:
224220
pipe.put_nowait(e)

modules/rpc_thread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import threading
33
import asyncio
44

5-
from modules import globals, async_thread, callbacks, msgbox, utils
65
from modules.structs import MsgBox
6+
from modules import globals, async_thread, callbacks, error, msgbox, utils
77

88
server: xmlrpc.server.SimpleXMLRPCServer = None
99
thread: threading.Thread = None
@@ -18,7 +18,7 @@ def run_loop():
1818
try:
1919
server = xmlrpc.server.SimpleXMLRPCServer(("localhost", globals.rpc_port), logRequests=False, allow_none=True)
2020
except Exception:
21-
raise msgbox.Exc("RPC server error", f"Failed to start RPC server on localhost port {globals.rpc_port}:\n{utils.get_error()}\n\nThis means that the web browser extension will not work, while F95Checker\nitself should be unaffected. Some common causes are:\n - Hyper-V\n - Docker\n - Antivirus or firewall", MsgBox.warn, more=utils.get_traceback())
21+
raise msgbox.Exc("RPC server error", f"Failed to start RPC server on localhost port {globals.rpc_port}:\n{error.text()}\n\nThis means that the web browser extension will not work, while F95Checker\nitself should be unaffected. Some common causes are:\n - Hyper-V\n - Docker\n - Antivirus or firewall", MsgBox.warn, more=error.traceback())
2222

2323
server.register_function(globals.gui.show, "show_window")
2424
def add_game(url):

modules/utils.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import OpenGL.GL as gl
33
import concurrent
44
import functools
5-
import traceback
65
import asyncio
76
import weakref
87
import typing
@@ -60,20 +59,6 @@ def reset_timer(_):
6059
globals.refresh_task.add_done_callback(done_callback)
6160

6261

63-
# https://gist.github.com/Willy-JL/f733c960c6b0d2284bcbee0316f88878
64-
def get_traceback(*exc_info: list):
65-
exc_info = exc_info or sys.exc_info()
66-
if len(exc_info) == 1:
67-
exc_info = type(exc_info), exc_info, exc_info.__traceback__
68-
tb_lines = traceback.format_exception(*exc_info)
69-
tb = "".join(tb_lines)
70-
return tb
71-
72-
def get_error(exc: Exception = None):
73-
exc = exc or sys.exc_info()[1]
74-
return f"{type(exc).__name__}: {str(exc) or 'No further details'}"
75-
76-
7762
class daemon:
7863
def __init__(self, proc):
7964
self.finalize = weakref.finalize(proc, self.kill, proc)

0 commit comments

Comments
 (0)