From 0c624b30c7404cd10c6c5447c916956c8d84961b Mon Sep 17 00:00:00 2001 From: Rahul Johny <116638720+johnyrahul@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:22:00 +0530 Subject: [PATCH] Logging unhandled errors (#76) * Logging unhandled errors * Including error trace in logs * Including error trace in logs * Updated version --- src/unstract/sdk/__init__.py | 2 +- src/unstract/sdk/tool/executor.py | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/unstract/sdk/__init__.py b/src/unstract/sdk/__init__.py index 1825e5f6..f92fbbe2 100644 --- a/src/unstract/sdk/__init__.py +++ b/src/unstract/sdk/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.38.0" +__version__ = "0.38.1" def get_sdk_version(): diff --git a/src/unstract/sdk/tool/executor.py b/src/unstract/sdk/tool/executor.py index 08660bae..08b7055e 100644 --- a/src/unstract/sdk/tool/executor.py +++ b/src/unstract/sdk/tool/executor.py @@ -1,4 +1,5 @@ import argparse +import logging import shutil from json import loads from pathlib import Path @@ -11,6 +12,8 @@ from unstract.sdk.tool.base import BaseTool from unstract.sdk.tool.validator import ToolValidator +logger = logging.getLogger(__name__) + class ToolExecutor: """Takes care of executing a tool's intended command.""" @@ -45,9 +48,7 @@ def execute_run(self, args: argparse.Namespace) -> None: args (argparse.Namespace): Parsed arguments to execute with """ if args.settings is None: - self.tool.stream_error_and_exit( - "--settings are required for RUN command" - ) + self.tool.stream_error_and_exit("--settings are required for RUN command") settings: dict[str, Any] = loads(args.settings) self._setup_for_run() @@ -62,9 +63,14 @@ def execute_run(self, args: argparse.Namespace) -> None: f"SDK Version: {get_sdk_version()}, " f"adapter Version: {get_adapter_version()}" ) - self.tool.run( - settings=settings, - input_file=self.tool.get_input_file(), - output_dir=self.tool.get_output_dir(), - ) + try: + self.tool.run( + settings=settings, + input_file=self.tool.get_input_file(), + output_dir=self.tool.get_output_dir(), + ) + except Exception as e: + logger.error(f"Error while tool run: {e}", stack_info=True, exc_info=True) + self.tool.stream_error_and_exit(f"Error while running tool: {str(e)}") + # TODO: Call tool method to validate if output was written