Skip to content

fix: replace 2 bare except with except Exception in xeH.py - #113

Open
KeloYuan wants to merge 1 commit into
fffonion:masterfrom
KeloYuan:fix/bare-except-xeH
Open

KeloYuan wants to merge 1 commit into
fffonion:masterfrom
KeloYuan:fix/bare-except-xeH

Conversation

@KeloYuan

Copy link
Copy Markdown

Replaced bare except: with except Exception: to avoid catching KeyboardInterrupt/SystemExit.

Co-authored-by: KeloYuan <keloyuan@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 10, 2026 10:16

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread xeH.py
try:
r = json.loads(z.read("info.json"))
except:
except Exception:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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:

  1. NameError: SRC_UPDATE_VERSION is used but not defined in this scope. It should be const.SRC_UPDATE_VERSION.
  2. Logic Error: The condition if 'v' not in r and r['v'] != SRC_UPDATE_VERSION: is incorrect. If 'v' is missing, it will raise a KeyError when attempting to access r['v']. If 'v' is present, the and will short-circuit and never check the version value. It should likely use or instead of and.

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.

Comment thread xeH.py
xeHentai.const.VERSION_UPDATE = update_id
xeHentai.const.VERSION_UPDATE_LOADER = v
except:
except Exception:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: with except Exception: when parsing info.json from src.zip.
  • Replace bare except: with except 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 evaluate r['v'] because the left side is True, raising a KeyError and skipping the intended legacy-handling path. This should be rewritten to avoid indexing r['v'] when the key is absent (likely using or, or r.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants