Catch and display errors from "Save As"

This commit is contained in:
Gnome Ann 2021-09-01 12:58:01 -04:00
parent e31640a89d
commit 16184ceee8
2 changed files with 16 additions and 4 deletions

View File

@ -1831,10 +1831,14 @@ def saveas(name):
name = utils.cleanfilename(name) name = utils.cleanfilename(name)
if(not fileops.saveexists(name) or (vars.saveow and vars.svowname == name)): if(not fileops.saveexists(name) or (vars.saveow and vars.svowname == name)):
# All clear to save # All clear to save
saveRequest(fileops.storypath(name)) e = saveRequest(fileops.storypath(name))
emit('from_server', {'cmd': 'hidesaveas', 'data': ''})
vars.saveow = False vars.saveow = False
vars.svowname = "" 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: else:
# File exists, prompt for overwrite # File exists, prompt for overwrite
vars.saveow = True vars.saveow = True
@ -1932,11 +1936,16 @@ def saveRequest(savpath):
}) })
# Write it # Write it
file = open(savpath, "w") try:
file = open(savpath, "w")
except Exception as e:
return e
try: try:
file.write(json.dumps(js, indent=3)) file.write(json.dumps(js, indent=3))
finally: except Exception as e:
file.close() file.close()
return e
file.close()
print("{0}Story saved to {1}!{2}".format(colors.GREEN, path.basename(savpath), colors.END)) print("{0}Story saved to {1}!{2}".format(colors.GREEN, path.basename(savpath), colors.END))

View File

@ -193,6 +193,9 @@
<div class="aidgpopupcontent"> <div class="aidgpopupcontent">
<input class="form-control" type="text" placeholder="Save Name" id="savename"> <input class="form-control" type="text" placeholder="Save Name" id="savename">
</div> </div>
<div class="popuperror hidden">
<span></span>
</div>
<div class="saveasoverwrite hidden"> <div class="saveasoverwrite hidden">
<span>File already exists. Really overwrite?</span> <span>File already exists. Really overwrite?</span>
</div> </div>