Skip to content

Commit

Permalink
Handle nonexistant analyzers
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
michaelweiser committed Jan 13, 2021
1 parent ee48cba commit a8fd358
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cortex4py/controllers/analyzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cortex4py.query import *
from .abstract import AbstractController
from ..models import Analyzer, Job, AnalyzerDefinition
from ..exceptions import CortexError


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

if analyzer is None:
raise CortexError("Analyzer %s not found" % analyzer_name)

return self.run_by_id(analyzer.id, observable, **kwargs)

0 comments on commit a8fd358

Please sign in to comment.