From 98971e23983a69933c44040e92e456745cc52715 Mon Sep 17 00:00:00 2001 From: Caleb R Little Date: Tue, 21 Sep 2021 17:15:40 -0400 Subject: [PATCH 1/3] Minor tweak to allow parsers to return 418 to signal that an ability failed based on the output of the parser --- app/objects/secondclass/c_link.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/objects/secondclass/c_link.py b/app/objects/secondclass/c_link.py index 4547dc049..49f594482 100644 --- a/app/objects/secondclass/c_link.py +++ b/app/objects/secondclass/c_link.py @@ -190,8 +190,13 @@ async def parse(self, operation, result): source_facts = operation.source.facts if operation else [] try: relationships = await self._parse_link_result(result, parser, source_facts) - await update_scores(operation, increment=len(relationships), used=self.used, facts=self.facts) - await self._create_relationships(relationships, operation) + if relationships == 418: + logging.getLogger('link').debug(f'link {self.id} (ability id={self.ability.ability_id}) during ' + f'execution, which was caught during parsing.') + self.status = self.states['ERROR'] + else: + await update_scores(operation, increment=len(relationships), used=self.used, facts=self.facts) + await self._create_relationships(relationships, operation) except Exception as e: logging.getLogger('link').debug('error in %s while parsing ability %s: %s' % (parser.module, self.ability.ability_id, e)) From 8d4432b889e5270d901dab3d3495a92d275b35d4 Mon Sep 17 00:00:00 2001 From: Caleb R Little Date: Wed, 22 Sep 2021 13:52:52 -0400 Subject: [PATCH 2/3] Code cleanup --- app/objects/secondclass/c_link.py | 11 +++++++---- app/utility/base_parser.py | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/objects/secondclass/c_link.py b/app/objects/secondclass/c_link.py index 49f594482..48d3ac773 100644 --- a/app/objects/secondclass/c_link.py +++ b/app/objects/secondclass/c_link.py @@ -13,6 +13,7 @@ from app.objects.secondclass.c_relationship import RelationshipSchema from app.objects.secondclass.c_visibility import Visibility, VisibilitySchema from app.utility.base_object import BaseObject +from app.utility.base_parser import PARSER_SIGNALS_FAILURE from app.utility.base_service import BaseService @@ -190,13 +191,15 @@ async def parse(self, operation, result): source_facts = operation.source.facts if operation else [] try: relationships = await self._parse_link_result(result, parser, source_facts) - if relationships == 418: - logging.getLogger('link').debug(f'link {self.id} (ability id={self.ability.ability_id}) during ' - f'execution, which was caught during parsing.') + + if relationships[0] == PARSER_SIGNALS_FAILURE: + logging.getLogger('link').debug(f'link {self.id} (ability id={self.ability.ability_id}) encountered ' + f'an error during execution, which was caught during parsing.') self.status = self.states['ERROR'] + relationships = [] # we didn't actually get anything out of this, so let's reset else: - await update_scores(operation, increment=len(relationships), used=self.used, facts=self.facts) await self._create_relationships(relationships, operation) + await update_scores(operation, increment=len(relationships), used=self.used, facts=self.facts) except Exception as e: logging.getLogger('link').debug('error in %s while parsing ability %s: %s' % (parser.module, self.ability.ability_id, e)) diff --git a/app/utility/base_parser.py b/app/utility/base_parser.py index 0ab7d7400..382e724f2 100644 --- a/app/utility/base_parser.py +++ b/app/utility/base_parser.py @@ -1,6 +1,8 @@ import json import re +PARSER_SIGNALS_FAILURE = 418 # Universal Teapot error code + class BaseParser: From 2783432525f559b744a48be9d7e57fca40de35b5 Mon Sep 17 00:00:00 2001 From: Caleb R Little Date: Wed, 22 Sep 2021 18:29:17 -0400 Subject: [PATCH 3/3] Tweak to remove potential error message --- app/objects/secondclass/c_link.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/objects/secondclass/c_link.py b/app/objects/secondclass/c_link.py index 48d3ac773..f3928a2c1 100644 --- a/app/objects/secondclass/c_link.py +++ b/app/objects/secondclass/c_link.py @@ -192,7 +192,7 @@ async def parse(self, operation, result): try: relationships = await self._parse_link_result(result, parser, source_facts) - if relationships[0] == PARSER_SIGNALS_FAILURE: + if len(relationships) > 0 and relationships[0] == PARSER_SIGNALS_FAILURE: logging.getLogger('link').debug(f'link {self.id} (ability id={self.ability.ability_id}) encountered ' f'an error during execution, which was caught during parsing.') self.status = self.states['ERROR']