Skip to content

Commit 0dc8670

Browse files
committed
Wrap every tool with exception handling
1 parent 5a9627a commit 0dc8670

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ 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+
return f"Error: {e}"
7881

7982
return execute_logging_wrapper

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "patchwork-cli"
3-
version = "0.0.112"
3+
version = "0.0.113.dev0"
44
description = ""
55
authors = ["patched.codes"]
66
license = "AGPL"

0 commit comments

Comments
 (0)