From 16184ceee89d9f1f762ab3c9c78e93f86fff5024 Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Wed, 1 Sep 2021 12:58:01 -0400 Subject: [PATCH] Catch and display errors from "Save As" --- aiserver.py | 17 +++++++++++++---- templates/index.html | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/aiserver.py b/aiserver.py index 2d050acd..3a2406cf 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1831,10 +1831,14 @@ def saveas(name): name = utils.cleanfilename(name) if(not fileops.saveexists(name) or (vars.saveow and vars.svowname == name)): # All clear to save - saveRequest(fileops.storypath(name)) - emit('from_server', {'cmd': 'hidesaveas', 'data': ''}) + e = saveRequest(fileops.storypath(name)) vars.saveow = False vars.svowname = "" + if(e is None): + emit('from_server', {'cmd': 'hidesaveas', 'data': ''}) + else: + print("{0}{1}{2}".format(colors.RED, str(e), colors.END)) + emit('from_server', {'cmd': 'popuperror', 'data': str(e)}) else: # File exists, prompt for overwrite vars.saveow = True @@ -1932,11 +1936,16 @@ def saveRequest(savpath): }) # Write it - file = open(savpath, "w") + try: + file = open(savpath, "w") + except Exception as e: + return e try: file.write(json.dumps(js, indent=3)) - finally: + except Exception as e: file.close() + return e + file.close() print("{0}Story saved to {1}!{2}".format(colors.GREEN, path.basename(savpath), colors.END)) diff --git a/templates/index.html b/templates/index.html index b0b7a3f8..f14a18eb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -193,6 +193,9 @@