From 622cb727fa05c2c9c7c216dfa299e7a82a390a67 Mon Sep 17 00:00:00 2001 From: igorski-r7 <99184344+igorski-r7@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:17:49 +0100 Subject: [PATCH] Python 3 Script - 414 - Removed unnecessarry error traceback from the plugin | Separated exceptions | Updated dependency path (#2136) --- .../icon_python_3_script/actions/run/action.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/python_3_script/icon_python_3_script/actions/run/action.py b/plugins/python_3_script/icon_python_3_script/actions/run/action.py index 3659a6bd87..7740fd7f6a 100755 --- a/plugins/python_3_script/icon_python_3_script/actions/run/action.py +++ b/plugins/python_3_script/icon_python_3_script/actions/run/action.py @@ -12,7 +12,7 @@ from .schema import Component, Input, RunInput, RunOutput -sys.path.append("/var/cache/python_dependencies/lib/python3.8/site-packages") +sys.path.append("/var/cache/python_dependencies/lib/python3.9/site-packages") class Run(insightconnect_plugin_runtime.Action): @@ -33,7 +33,7 @@ def run(self, params={}): try: output = self._execute_function_as_process(function_, params.get(Input.INPUT, {})) except Exception as error: - raise PluginException(cause="Could not run supplied script", data=str(error)) + raise PluginException(cause="Could not run supplied script", data=error) from None try: if output is None: raise PluginException( @@ -85,15 +85,17 @@ def _execute_function_as_process(function_: str, parameters: Dict[str, Any]) -> [ "python", "-c", - f'import sys\n\n{function_}\nsys.stdout.write("{execution_id}" + str({function_name}({parameters})))', + f'import sys\n\nsys.path.append("/var/cache/python_dependencies/lib/python3.9/site-packages")\n\n{function_}\nsys.stdout.write("{execution_id}" + str({function_name}({parameters})))', ], shell=False, stderr=subprocess.PIPE, timeout=DEFAULT_PROCESS_TIMEOUT, ) return extract_output_from_stdout(output.decode(DEFAULT_ENCODING), execution_id) - except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error: - raise PluginException(error.stderr.decode(DEFAULT_ENCODING)) + except subprocess.CalledProcessError as error: + raise PluginException(error.stderr.decode(DEFAULT_ENCODING)) from None + except subprocess.TimeoutExpired: + raise PluginException(f"Function got timed out after {DEFAULT_PROCESS_TIMEOUT} seconds.") from None @staticmethod def _add_credentials_to_function(