Skip to content

Commit

Permalink
Merge pull request #192 from google/python-tweaks
Browse files Browse the repository at this point in the history
Python tweaks
  • Loading branch information
kex103 authored Nov 15, 2023
2 parents d536226 + 4bace43 commit 080096e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion seeds/pythonboard/src/breadboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ async def run(
if type(handler) == javascript.proxy.Proxy:
# This can possibly be wrapped in an AsyncTask instead of a trivial coroutine
async def await_js(func, args):
res = func(args)
if func.invoke:
res = func.invoke(args)
else:
res = func(args)
# Outputs can be a javascript proxy, so convert to dict
try:
res = {k: res[k] for k in res}
Expand Down
26 changes: 18 additions & 8 deletions seeds/pythonboard/src/traversal/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ def _processCompletedNode(
if outputs.get("$error") and not any(e.out == "$error" for e in newOpportunities):
# If the node threw an exception and it wasn't routed via $error,
# throw it again. This will cause the traversal to stop.
raise Exception(
"Uncaught exception in node handler. " +
"Catch by wiring up the $error output.",
{
"cause": outputs["$error"],
}
)
if isinstance(outputs.get("$error").error, Exception):
raise Exception(
"Uncaught exception in node handler. " +
"Catch by wiring up the $error output.",
{
"cause": outputs["$error"],
}
) from outputs.get("$error").error
else:
raise Exception(
"Uncaught exception in node handler. " +
"Catch by wiring up the $error output.",
{
"cause": outputs["$error"],
}
)

@staticmethod
async def processAllPendingNodes(
Expand Down Expand Up @@ -89,7 +98,8 @@ async def _promise():
# If not already present, add inputs and descriptor along for
# context and to support retries.
if "$error" in outputs:
outputs["$error"] = outputs["$error"] | {
error_dict = {k: outputs["$error"][k] for k in outputs["$error"]}
outputs["$error"] = error_dict | {
"descriptor": descriptor,
"inputs": inputs,
}
Expand Down

0 comments on commit 080096e

Please sign in to comment.