Skip to content

Commit

Permalink
add warning for proton exception bug
Browse files Browse the repository at this point in the history
  • Loading branch information
apple1417 committed Jan 6, 2024
1 parent 983943c commit 9046f7d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections.abc import Collection, Iterator
from pathlib import Path

import unrealsdk
from unrealsdk import logging

# If true, displays the full traceback when a mod fails to import, rather than the shortened one
Expand Down Expand Up @@ -222,6 +223,46 @@ def import_mods() -> None:
logging.error("".join(traceback.format_list(tb)))


def proton_null_exception_check() -> None:
"""
Tries to detect and warn if we're running under a version of Proton which has the exception bug.
For context, usually pybind detects exceptions using a catch all, which eventually calls through
to `std::current_exception` to get the exact exception, and then runs a bunch of translators on
it to convert it to a Python exception. When running under a bad Proton version, this call
fails, and returns an empty exception pointer, so pybind is unable to translate it.
This means Python throws a:
```
SystemError: <built-in method __getattr__ of PyCapsule object at 0x00000000069AC780> returned NULL without setting an exception
```
This is primarily a problem for `StopIteration`.
""" # noqa: E501

cls = unrealsdk.find_class("Object")
try:
# Cause an attribute error
_ = cls._check_for_proton_null_exception_bug
except AttributeError:
# Working properly
return
except SystemError:
# Have the bug
logging.error(
"===============================================================================",
)
traceback.print_exc()
logging.error(
"\n"
"Some particular Proton versions cause this, try switch to another one.\n"
"Alternatively, the nightly release has builds from other compilers, which may also"
" prevent it.\n"
"\n"
"Will attempt to import mods, but they'll likely break with a similar error.\n"
"===============================================================================",
)


# Don't really want to put a `__name__` check here, since it's currently just `builtins`, and that
# seems a bit unstable, like something that pybind might eventually change

Expand All @@ -230,5 +271,7 @@ def import_mods() -> None:
while not logging.is_console_ready():
pass

proton_null_exception_check()

import_mod_manager()
import_mods()

0 comments on commit 9046f7d

Please sign in to comment.