From 00cf85ec0132e9968e54f3baa98594d14bbde271 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 15 Nov 2019 16:22:15 +0100 Subject: [PATCH] Catch corrupt condition method --- hugvey/story.py | 8 +++++++- hugvey/tools.py | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hugvey/story.py b/hugvey/story.py index 07a753b..ca0aa91 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -363,7 +363,13 @@ class Condition(object): """ Validate if condition is met for the current story state """ - return self.method(story) + try: + r = self.method(story) + except Exception as e: + story.logger.critical("Exception condition: {self.id}, ignoring it") + story.logger.exception(e) + r = False + return r def _hasMetTimeout(self, story): now = story.timer.getElapsed() diff --git a/hugvey/tools.py b/hugvey/tools.py index 19bacc0..6793ee6 100644 --- a/hugvey/tools.py +++ b/hugvey/tools.py @@ -3,6 +3,7 @@ import yaml import os import json from hugvey.voice import VoiceStorage +import re logger = logging.getLogger('toolbox') @@ -132,7 +133,7 @@ class Toolbox: if len(beginnings) < 1: logger.critical("No beginning set") if len(beginnings) > 1: - logger.critical(f"{len(beginnings)} beginning messages configured. Set only one") + logger.warn(f"{len(beginnings)} beginning messages configured. Set only one") itemsPerId = {item['@id']: item for item in story} @@ -153,6 +154,13 @@ class Toolbox: msgId = item['vars']['msgId'].strip() if msgId not in itemsPerId: logger.critical(f"Message played condition for non-existing message {msgId}!") + if item['type'] == 'replyContains': + if 'regex' in item['vars'] and len(item['vars']['regex'].rstrip()): + try: + re.compile(item['vars']['regex'].rstrip()) + except Exception as e: + logger.critical(f"Invalid regex for condition {item['@id']}: {item['vars']['regex'].rstrip()}") + logger.exception(e) with open(filename, 'w') as fp: json.dump(story, fp, indent=2)