Moo-Ack-Productions / MCprep

Blender python addon to increase workflow for creating minecraft renders and animations
https://theduckcow.com/MCprep
GNU General Public License v3.0
287 stars 24 forks source link

fix: Gracefully handle exceptions during direct i18n loading #628

Closed StandingPadAnimations closed 3 months ago

StandingPadAnimations commented 3 months ago

If translations.py doesn't exist, MCprep moves to direct i18n, which directly uses MO files for translations (at the cost of some UI updating issues). However, if these MO files do not exist, then MCprep will throw an exception. Since this exception occurs in the creation of MCprepEnv, MCprep is rendered unusable.

This patch adds a basic try-except statement to allow MCprepEnv to handle these exceptions gracefully.

TheDuckCow commented 3 months ago

Can you share the code to auto run the translations again? ie the bash command so I can insert them into the push_latest.sh script. There I can do a check that makes it auto-quit if there are untracked changes (or, should we always just auto-commit machine translation updates?). In that PR I'll also fix the usage of bab instead of the old builder, rather confused how we didn't run into this in the last release. I was probably lucky and did a single non-dev build with bab locally before running the main script

StandingPadAnimations commented 3 months ago

Sure

bab -b translate
TheDuckCow commented 3 months ago

Hm that command was already there, but I guess it comes back down to it being the old pre-bab command.

TheDuckCow commented 3 months ago

Looks like it wasn't all the way graceful, had to pull the v3.6.1.1 release after publishign as testing the build locally now ran into this issue, which now seems to always trigger even with translations. Now I'm not even sure why the automated tests aren't catching this, since there are enable/disable tests that should be occurring. I'm less familiar with this module

Addon.APIRC, ERROR, ThreadPoolExecutor-0_0, 11:15:20, api_remote_control_params.py/_get_user_info_from_api:266: Not authorized
Addon.APIRC, ERROR, ThreadPoolExecutor-0_0, 11:15:20, api_remote_control_params.py/thread_execute:282: get_user_info failed: Not authorized
Addon, WARNING, API RC Collect, 11:15:20, toolbox.py/callback_get_user_data_done:593: callback_get_user_data_done NOK
Traceback (most recent call last):
  File "/Applications/Blender 4.3/blender.app/Contents/Resources/4.3/scripts/modules/addon_utils.py", line 407, in enable
    mod = importlib.import_module(module_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Applications/Blender 4.3/blender.app/Contents/Resources/4.3/python/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/__init__.py", line 59, in <module>
    from . import load_modules
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/load_modules.py", line 118, in <module>
    from . import mcprep_ui
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/mcprep_ui.py", line 106, in <module>
    class MCPREP_MT_mob_spawner(bpy.types.Menu):
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/mcprep_ui.py", line 108, in MCPREP_MT_mob_spawner
    bl_label = env._("Mob Spawner")
               ^^^^^^^^^^^^^^^^^^^^
  File "/Users/patrickcrawford/Library/Application Support/Blender/4.3/scripts/addons/MCprep_addon/conf.py", line 166, in _
    if bpy.context.preferences.view.language in self.languages:
                                                ^^^^^^^^^^^^^^
AttributeError: 'MCprepEnv' object has no attribute 'languages'

Working on another patch for you to review.