Skip to content

Commit

Permalink
Prevent application crash on Save Session (#336)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesco Ceruti <[email protected]>
  • Loading branch information
essboyer and FrancescoCeruti authored Jan 5, 2025
1 parent f1df767 commit a8a9585
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions lisp/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,37 @@ def __save_to_file(self, session_file):
"session": session_props,
"cues": session_cues,
}

if self.conf.get("session.minSave", False):
dump_options = {"separators": (",", ":")}
else:
dump_options = {"sort_keys": True, "indent": 4}

# Write to a file the json-encoded session
with open(session_file, mode="w", encoding="utf-8") as file:
if self.conf.get("session.minSave", False):
dump_options = {"separators": (",", ":")}
else:
dump_options = {"sort_keys": True, "indent": 4}

file.write(json.dumps(session_dict, **dump_options))
# Serialize the session in a JSON string, and overwrite the active session file
try:
session_json = json.dumps(session_dict, **dump_options)
except TypeError:
logger.exception(
translate(
"ApplicationError",
"""
Error while writing the session file "{}"\n
Due to bad data, the session cannot be saved.
Please check any recent changes to cue pipelines.
""",
).format(session_file)
)
else:
with open(session_file, mode="w", encoding="utf-8") as file:
file.write(session_json)

# Save last session path
self.conf.set("session.lastPath", dirname(session_file))
self.conf.write()
# Save last session path
self.conf.set("session.lastPath", dirname(session_file))
self.conf.write()

# Set the session as saved
self.commands_stack.set_saved()
self.window.updateWindowTitle()
# Set the session as saved
self.commands_stack.set_saved()
self.window.updateWindowTitle()

def __load_from_file(self, session_file):
"""Load a saved session from file"""
Expand Down

0 comments on commit a8a9585

Please sign in to comment.