Skip to content

Commit

Permalink
Capture exceptions when walkthrough scanner stops unexpectedly (#128)
Browse files Browse the repository at this point in the history
Catch errors that happen during the walkthrough scanner to reduce noise,
especially when the game is closed unexpectedly. Cleans up the console
and logs when the player closes the game.
  • Loading branch information
jmctune authored Oct 9, 2023
1 parent 02a8436 commit 3ee60e1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/clarity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from common.db_ops import sql_read, sql_write
from common.errors import MemoryReadError
from common.lib import (
get_project_root,
is_dqx_process_running,
Expand All @@ -17,6 +18,7 @@
walkthrough_pattern,
)
from common.translate import convert_into_eng, detect_lang, Translate
from pymem.exception import WinAPIError

import re
import sys
Expand Down Expand Up @@ -232,12 +234,21 @@ def loop_scan_for_walkthrough():
time.sleep(1)
else:
time.sleep(1)
except WinAPIError as e:
if e.error_code == 299: # usually means the user closed the game.
if not is_dqx_process_running():
sys.exit(0)
raise(e)
except MemoryReadError as e:
if not is_dqx_process_running():
sys.exit(0)
raise(e)
except Exception:
if not is_dqx_process_running():
log.exception("A problem with the walkthrough scanner was detected.")
sys.exit(1)
sys.exit(0)
else:
log.exception("Problem detected running walkthrough scanner.")
log.exception("Problem was detected with the walkthrough scanner.")
sys.exit(1)


def run_scans(player_names=True, npc_names=True):
Expand Down

0 comments on commit 3ee60e1

Please sign in to comment.