Conversation
Co-authored-by: KeloYuan <keloyuan@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request replaces bare except clauses with except Exception in xeH.py to improve error handling. The review feedback identifies critical issues in the surrounding logic, including a NameError for an undefined variable and a logic error in a version check that would cause a KeyError. Additionally, it is recommended to log caught exceptions rather than swallowing them to facilitate debugging.
| try: | ||
| r = json.loads(z.read("info.json")) | ||
| except: | ||
| except Exception: |
There was a problem hiding this comment.
While replacing the bare except is a good practice, the logic in the following else block (line 25) contains two significant issues that will cause the update process to fail:
- NameError:
SRC_UPDATE_VERSIONis used but not defined in this scope. It should beconst.SRC_UPDATE_VERSION. - Logic Error: The condition
if 'v' not in r and r['v'] != SRC_UPDATE_VERSION:is incorrect. If'v'is missing, it will raise aKeyErrorwhen attempting to accessr['v']. If'v'is present, theandwill short-circuit and never check the version value. It should likely useorinstead ofand.
Since these issues lead to an exception that triggers the outer handler and deletes the update file, they should be addressed to make the update mechanism functional.
| xeHentai.const.VERSION_UPDATE = update_id | ||
| xeHentai.const.VERSION_UPDATE_LOADER = v | ||
| except: | ||
| except Exception: |
There was a problem hiding this comment.
Swallowing all exceptions silently here makes it difficult to debug issues with the update process, such as syntax errors in the downloaded code or a corrupted zip file. Consider logging the error or printing it to sys.stderr before proceeding with the cleanup.
except Exception as e:
sys.stderr.write("Failed to load update: %s\n" % e)There was a problem hiding this comment.
Pull request overview
This PR updates the bootstrap updater loader (xeH.py) to avoid catching KeyboardInterrupt/SystemExit by replacing two bare except: blocks with except Exception:.
Changes:
- Replace bare
except:withexcept Exception:when parsinginfo.jsonfromsrc.zip. - Replace bare
except:withexcept Exception:around the update-load/reload sequence.
Comments suppressed due to low confidence (1)
xeH.py:26
- The version gate condition is currently
if 'v' not in r and r['v'] != SRC_UPDATE_VERSION:. When'v'is missing (the legacy case you’re trying to detect), Python will still evaluater['v']because the left side is True, raising aKeyErrorand skipping the intended legacy-handling path. This should be rewritten to avoid indexingr['v']when the key is absent (likely usingor, orr.get('v')).
except Exception:
need_remove = True
else:
if 'v' not in r and r['v'] != SRC_UPDATE_VERSION:
# ignoring legacy file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replaced bare except: with except Exception: to avoid catching KeyboardInterrupt/SystemExit.