cauldron / activity-browser

GUI for Brightway
GNU Lesser General Public License v3.0
0 stars 3 forks source link

App will crash if settings is invalid #22

Closed ughstudios closed 5 months ago

ughstudios commented 5 months ago

Updating AB

What happened?

If the ABsettings.json file is somehow corrupted, or invalid. The app will crash without informing the user as to why. The app will also not log or tell the user what went wrong. I noticed this because my settings file somehow became like this:

{
    "current_bw_dir": 

And when I tried to load the app it kept failing with no errors or log output. This happens in update_old_settings in settings.py when it tries to load up the settings file. The global except handler has not been setup at this point as well.

It will simply try to load and then fail with no output:

(ab) (base) danielgleason@Daniels-MacBook-Pro activity-browser %  cd /Users/danielgleason/Desktop/cauldron_activity_browser/activity-browser ; /u
sr/bin/env /opt/homebrew/Caskroom/miniconda/base/envs/ab/bin/python3.10 /Users/danielgleason/.vscode/extensions/ms-python.debugpy-2024.6.0-darwin
-arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher 55428 -- run-activity-browser.py 
 INFO   Info: GPU hardware acceleration disabled

Relevant errors

We just need to update the code so that it will properly print out the exception. Something is hiding the error. I imagine it's probably one of those broad except handlers somewhere.

json.dump(self.settings, outfile, indent=4, sort_keys=True)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ab/lib/python3.10/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ab/lib/python3.10/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ab/lib/python3.10/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ab/lib/python3.10/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/ab/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PosixPath is not JSON serializable

Operating system

MacOS

Conda environment

No response

ughstudios commented 5 months ago

So somehow it's detecting my paths as PosixPaths here and that's why it's not able to save and serialize my settings.