Skip to content

Commit

Permalink
[TRY-CATCH]: Enhancement on else (catch) block; Fix uncovered run act…
Browse files Browse the repository at this point in the history
…ion on try catch
  • Loading branch information
amadolid committed Sep 1, 2023
1 parent 125fc87 commit 1515895
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
5 changes: 2 additions & 3 deletions jaseci_core/jaseci/extens/act_lib/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ def actload_local(filename: str, meta):
"""
mast = master_from_meta(meta)
if not mast.is_master(super_check=True, silent=True):
meta["interp"].rt_error(
"Only super master can load actions.", meta["interp"]._cur_jac_ast
)
raise Exception("Only super master can load actions.")

return mast.actions_load_local(file=filename)["success"]


Expand Down
4 changes: 3 additions & 1 deletion jaseci_core/jaseci/jac/interpreter/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ def run_try_stmt(self, jac_ast):
self._jac_try_mode += 1
try:
self.run_code_block(kid[1])
self._jac_try_mode -= 1
except TryException as e:
self._jac_try_mode -= 1
if len(kid) > 2:
self.run_else_from_try(kid[2], e.ref)
except Exception as e:
self._jac_try_mode -= 1
if len(kid) > 2:
self.run_else_from_try(kid[2], self.jac_exception(e, kid[2]))
self._jac_try_mode -= 1

def run_else_from_try(self, jac_ast, jac_ex):
"""
Expand Down
19 changes: 7 additions & 12 deletions jaseci_core/jaseci/prim/ability.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,17 @@ def run_action(self, param_list, scope, interp, jac_ast):
action_manager.pre_action_call_hook()

ts = time.time()
if "meta" in args:
result = func(
*param_list["args"],
**param_list["kwargs"],
meta={
try:
if "meta" in args:
param_list["kwargs"]["meta"] = {
"m_id": scope.parent._m_id,
"h": scope.parent._h,
"scope": scope,
"interp": interp,
},
)
else:
try:
result = func(*param_list["args"], **param_list["kwargs"])
except Exception as e:
interp.rt_error(e, jac_ast, True)
}
result = func(*param_list["args"], **param_list["kwargs"])
except Exception as e:
interp.rt_error(e, jac_ast, True)
t = time.time() - ts
action_manager.post_action_call_hook(action_name, t)
return result
Expand Down
2 changes: 1 addition & 1 deletion jaseci_core/jaseci/tests/test_progs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_action_load_std_lib_only_super(self):
self.assertFalse(report["success"])
self.assertEqual(
[
"test:aload - line 3, col 33 - rule expr_list - Only super master can load actions."
"test:aload - line 3, col 32 - rule ability_call - Only super master can load actions."
],
report["errors"],
)
Expand Down

0 comments on commit 1515895

Please sign in to comment.