11import argparse
2+ import logging
23import shutil
34from json import loads
45from pathlib import Path
1112from unstract .sdk .tool .base import BaseTool
1213from unstract .sdk .tool .validator import ToolValidator
1314
15+ logger = logging .getLogger (__name__ )
16+
1417
1518class 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