From 857fefdce073c896c80abb501186ee9420188643 Mon Sep 17 00:00:00 2001 From: "Alexie (Boyong) Madolid" Date: Fri, 1 Sep 2023 13:17:09 +0800 Subject: [PATCH] [TRY-CATCH]: Enhancement on else (catch) block; Fix uncovered run action on try catch --- jaseci_core/jaseci/extens/act_lib/std.py | 5 ++--- jaseci_core/jaseci/jac/interpreter/interp.py | 4 +++- jaseci_core/jaseci/prim/ability.py | 19 +++++++------------ jaseci_core/jaseci/tests/test_progs.py | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/jaseci_core/jaseci/extens/act_lib/std.py b/jaseci_core/jaseci/extens/act_lib/std.py index c4566ec78e..94dbb2a569 100644 --- a/jaseci_core/jaseci/extens/act_lib/std.py +++ b/jaseci_core/jaseci/extens/act_lib/std.py @@ -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"] diff --git a/jaseci_core/jaseci/jac/interpreter/interp.py b/jaseci_core/jaseci/jac/interpreter/interp.py index 03c101c5ae..b9fd210f20 100644 --- a/jaseci_core/jaseci/jac/interpreter/interp.py +++ b/jaseci_core/jaseci/jac/interpreter/interp.py @@ -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): """ diff --git a/jaseci_core/jaseci/prim/ability.py b/jaseci_core/jaseci/prim/ability.py index d785753d24..9981ee71c1 100644 --- a/jaseci_core/jaseci/prim/ability.py +++ b/jaseci_core/jaseci/prim/ability.py @@ -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 diff --git a/jaseci_core/jaseci/tests/test_progs.py b/jaseci_core/jaseci/tests/test_progs.py index 661170a431..cbb79a0ef8 100644 --- a/jaseci_core/jaseci/tests/test_progs.py +++ b/jaseci_core/jaseci/tests/test_progs.py @@ -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"], )