Skip to content

Commit

Permalink
Add try/catch around node execution.
Browse files Browse the repository at this point in the history
  • Loading branch information
syamajala committed Sep 16, 2019
1 parent fc04e39 commit 3093383
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions networkfox/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,32 @@
from .modifiers import optional


# class GraphExecutionException(Exception):

# def __init__(self, node_name, exception):
# self.node_name = node_name
# self.exception = exception


class FunctionalOperation(Operation):
def __init__(self, **kwargs):
self.fn = kwargs.pop('fn')
Operation.__init__(self, **kwargs)

def _compute(self, named_inputs, outputs=None):

inputs = [named_inputs[d.name] for d in self.needs if not d.optional]

# Find any optional inputs in named_inputs. Get only the ones that
# are present there, no extra `None`s.
optionals = {n.name: named_inputs[n.name] for n in self.needs if n.optional and n.name in named_inputs}

# Combine params and optionals into one big glob of keyword arguments.
kwargs = {k: v for d in (self.params, optionals) for k, v in d.items()}
result = self.fn(*inputs, **kwargs)
try:
result = self.fn(*inputs, **kwargs)
except Exception as e:
e.node_name = self.name
raise e

if len(self.provides) == 1:
result = [result]

Expand Down

0 comments on commit 3093383

Please sign in to comment.