Skip to content

Commit

Permalink
Logging unhandled errors (#76)
Browse files Browse the repository at this point in the history
* Logging unhandled errors

* Including error trace in logs

* Including error trace in logs

* Updated version
  • Loading branch information
johnyrahul authored Jul 24, 2024
1 parent c8d93f8 commit 0c624b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/unstract/sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.38.0"
__version__ = "0.38.1"


def get_sdk_version():
Expand Down
22 changes: 14 additions & 8 deletions src/unstract/sdk/tool/executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import logging
import shutil
from json import loads
from pathlib import Path
Expand All @@ -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."""
Expand Down Expand Up @@ -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()
Expand All @@ -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

0 comments on commit 0c624b3

Please sign in to comment.