From bf2b02d366b93c456c2df927ccac0686eafd6fda Mon Sep 17 00:00:00 2001 From: Gnome Ann <> Date: Fri, 21 Jan 2022 21:19:32 -0500 Subject: [PATCH] Don't error in `update_story_chunk` if chunk index doesn't exist --- aiserver.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/aiserver.py b/aiserver.py index 0d32a014..8284a605 100644 --- a/aiserver.py +++ b/aiserver.py @@ -3237,6 +3237,8 @@ def update_story_chunk(idx: Union[int, str]): else: # Actions are 0 based, but in chunks 0 is the prompt. # So the chunk index is one more than the corresponding action index. + if(idx - 1 not in vars.actions): + return text = vars.actions[idx - 1] item = html.escape(text) @@ -3365,7 +3367,9 @@ def inlineedit(chunk, data): else: if(chunk-1 in vars.actions): vars.actions[chunk-1] = data - + else: + print(f"WARNING: Attempted to edit non-existent chunk {chunk}") + setgamesaved(False) update_story_chunk(chunk) emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True) @@ -3386,6 +3390,8 @@ def inlinedelete(chunk): else: if(chunk-1 in vars.actions): del vars.actions[chunk-1] + else: + print(f"WARNING: Attempted to delete non-existent chunk {chunk}") setgamesaved(False) remove_story_chunk(chunk) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)