Skip to content

Commit 4598b71

Browse files
authored
Wrap every tool with exception handling (#1472)
* Wrap every tool with exception handling * add general logging error * lint and update lockfile
1 parent 5a9627a commit 4598b71

File tree

5 files changed

+631
-284
lines changed

5 files changed

+631
-284
lines changed

patchwork/common/tools/grep_tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def execute(
164164
is_case_sensitive: bool = False,
165165
) -> str:
166166
if pattern is None:
167-
raise ValueError("pattern argument is required!")
167+
return "`pattern` argument is required!"
168168

169169
if path is None:
170170
path = Path(self.__working_dir)
@@ -173,9 +173,12 @@ def execute(
173173
if is_case_sensitive:
174174
matcher = fnmatch.fnmatchcase
175175

176-
path = Path(path).resolve()
176+
try:
177+
path = Path(path).resolve()
178+
except FileNotFoundError:
179+
return f"`path` does not exist"
177180
if not path.is_relative_to(self.__working_dir):
178-
raise ValueError("Path must be relative to working dir")
181+
return f"Path must be relative to working dir {self.__working_dir}"
179182

180183
if path.is_file():
181184
paths = [path]

patchwork/common/tools/tool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def execute_logging_wrapper(self, *args, **kwargs):
7474
arg_text += f"kwargs: {kwargs}"
7575

7676
logger.info(f"Executing Tool: {self.name} with {arg_text}")
77-
return func(self, *args, **kwargs)
77+
try:
78+
return func(self, *args, **kwargs)
79+
except Exception as e:
80+
logger.error(f"Error executing Tool: {self.name}: {e}")
81+
return f"Error: {e}"
7882

7983
return execute_logging_wrapper

patchwork/common/utils/zoho_token_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
2-
import yaml
31
import time
4-
import requests
5-
from typing import Dict, Optional, Callable
62
from pathlib import Path
3+
from typing import Callable, Dict, Optional
4+
5+
import requests
6+
import yaml
77

88

99
class ZohoTokenManager:

0 commit comments

Comments
 (0)