Catch corrupt condition method

This commit is contained in:
Ruben van de Ven 2019-11-15 16:22:15 +01:00
parent bf3c9cc962
commit 00cf85ec01
2 changed files with 16 additions and 2 deletions

View file

@ -363,7 +363,13 @@ class Condition(object):
""" """
Validate if condition is met for the current story state 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): def _hasMetTimeout(self, story):
now = story.timer.getElapsed() now = story.timer.getElapsed()

View file

@ -3,6 +3,7 @@ import yaml
import os import os
import json import json
from hugvey.voice import VoiceStorage from hugvey.voice import VoiceStorage
import re
logger = logging.getLogger('toolbox') logger = logging.getLogger('toolbox')
@ -132,7 +133,7 @@ class Toolbox:
if len(beginnings) < 1: if len(beginnings) < 1:
logger.critical("No beginning set") logger.critical("No beginning set")
if len(beginnings) > 1: 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} itemsPerId = {item['@id']: item for item in story}
@ -153,6 +154,13 @@ class Toolbox:
msgId = item['vars']['msgId'].strip() msgId = item['vars']['msgId'].strip()
if msgId not in itemsPerId: if msgId not in itemsPerId:
logger.critical(f"Message played condition for non-existing message {msgId}!") 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: with open(filename, 'w') as fp:
json.dump(story, fp, indent=2) json.dump(story, fp, indent=2)