Skip to content

Commit a8fd358

Browse files
committed
Handle nonexistant analyzers
Trying to submit to an analyzer that is not configured results in an AttributeError because property id of the analyzer object is accessed regardless of the result of get_by_name: File "/cortex4py/cortex4py/controllers/analyzers.py", line 90, in run_by_name return self.run_by_id(analyzer.id, observable, **kwargs) AttributeError: 'NoneType' object has no attribute 'id' Add a check for the result of get_by_name() and throw a CortexError with explanatory message on failure. Signed-off-by: Michael Weiser <michael.weiser@gmx.de>
1 parent ee48cba commit a8fd358

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

cortex4py/controllers/analyzers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from cortex4py.query import *
88
from .abstract import AbstractController
99
from ..models import Analyzer, Job, AnalyzerDefinition
10+
from ..exceptions import CortexError
1011

1112

1213
class AnalyzersController(AbstractController):
@@ -87,4 +88,7 @@ def run_by_id(self, analyzer_id, observable, **kwargs) -> Job:
8788
def run_by_name(self, analyzer_name, observable, **kwargs) -> Job:
8889
analyzer = self.get_by_name(analyzer_name)
8990

91+
if analyzer is None:
92+
raise CortexError("Analyzer %s not found" % analyzer_name)
93+
9094
return self.run_by_id(analyzer.id, observable, **kwargs)

0 commit comments

Comments
 (0)