Skip to content

Commit 0c624b3

Browse files
authored
Logging unhandled errors (#76)
* Logging unhandled errors * Including error trace in logs * Including error trace in logs * Updated version
1 parent c8d93f8 commit 0c624b3

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/unstract/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.38.0"
1+
__version__ = "0.38.1"
22

33

44
def get_sdk_version():

src/unstract/sdk/tool/executor.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import logging
23
import shutil
34
from json import loads
45
from pathlib import Path
@@ -11,6 +12,8 @@
1112
from unstract.sdk.tool.base import BaseTool
1213
from unstract.sdk.tool.validator import ToolValidator
1314

15+
logger = logging.getLogger(__name__)
16+
1417

1518
class ToolExecutor:
1619
"""Takes care of executing a tool's intended command."""
@@ -45,9 +48,7 @@ def execute_run(self, args: argparse.Namespace) -> None:
4548
args (argparse.Namespace): Parsed arguments to execute with
4649
"""
4750
if args.settings is None:
48-
self.tool.stream_error_and_exit(
49-
"--settings are required for RUN command"
50-
)
51+
self.tool.stream_error_and_exit("--settings are required for RUN command")
5152
settings: dict[str, Any] = loads(args.settings)
5253

5354
self._setup_for_run()
@@ -62,9 +63,14 @@ def execute_run(self, args: argparse.Namespace) -> None:
6263
f"SDK Version: {get_sdk_version()}, "
6364
f"adapter Version: {get_adapter_version()}"
6465
)
65-
self.tool.run(
66-
settings=settings,
67-
input_file=self.tool.get_input_file(),
68-
output_dir=self.tool.get_output_dir(),
69-
)
66+
try:
67+
self.tool.run(
68+
settings=settings,
69+
input_file=self.tool.get_input_file(),
70+
output_dir=self.tool.get_output_dir(),
71+
)
72+
except Exception as e:
73+
logger.error(f"Error while tool run: {e}", stack_info=True, exc_info=True)
74+
self.tool.stream_error_and_exit(f"Error while running tool: {str(e)}")
75+
7076
# TODO: Call tool method to validate if output was written

0 commit comments

Comments
 (0)