Spaces:
Running
Running
Jeremiah Lowin Claude commited on
Commit ·
7d648cc
1
Parent(s): 68ca900
Fix duplicate error logging in exception handlers
Browse filesRemove redundant `{e}` interpolation from logger.exception() calls.
Since logger.exception() automatically logs the full exception traceback,
including `{e}` in the message causes duplicate error output.
Fixes #936
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
src/fastmcp/prompts/prompt.py
CHANGED
|
@@ -339,6 +339,6 @@ class FunctionPrompt(Prompt):
|
|
| 339 |
raise PromptError("Could not convert prompt result to message.")
|
| 340 |
|
| 341 |
return messages
|
| 342 |
-
except Exception
|
| 343 |
-
logger.exception(f"Error rendering prompt {self.name}
|
| 344 |
raise PromptError(f"Error rendering prompt {self.name}.")
|
|
|
|
| 339 |
raise PromptError("Could not convert prompt result to message.")
|
| 340 |
|
| 341 |
return messages
|
| 342 |
+
except Exception:
|
| 343 |
+
logger.exception(f"Error rendering prompt {self.name}")
|
| 344 |
raise PromptError(f"Error rendering prompt {self.name}.")
|
src/fastmcp/prompts/prompt_manager.py
CHANGED
|
@@ -172,12 +172,12 @@ class PromptManager:
|
|
| 172 |
|
| 173 |
# Pass through PromptErrors as-is
|
| 174 |
except PromptError as e:
|
| 175 |
-
logger.exception(f"Error rendering prompt {name!r}
|
| 176 |
raise e
|
| 177 |
|
| 178 |
# Handle other exceptions
|
| 179 |
except Exception as e:
|
| 180 |
-
logger.exception(f"Error rendering prompt {name!r}
|
| 181 |
if self.mask_error_details:
|
| 182 |
# Mask internal details
|
| 183 |
raise PromptError(f"Error rendering prompt {name!r}") from e
|
|
|
|
| 172 |
|
| 173 |
# Pass through PromptErrors as-is
|
| 174 |
except PromptError as e:
|
| 175 |
+
logger.exception(f"Error rendering prompt {name!r}")
|
| 176 |
raise e
|
| 177 |
|
| 178 |
# Handle other exceptions
|
| 179 |
except Exception as e:
|
| 180 |
+
logger.exception(f"Error rendering prompt {name!r}")
|
| 181 |
if self.mask_error_details:
|
| 182 |
# Mask internal details
|
| 183 |
raise PromptError(f"Error rendering prompt {name!r}") from e
|
src/fastmcp/resources/resource_manager.py
CHANGED
|
@@ -422,12 +422,12 @@ class ResourceManager:
|
|
| 422 |
|
| 423 |
# raise ResourceErrors as-is
|
| 424 |
except ResourceError as e:
|
| 425 |
-
logger.exception(f"Error reading resource {uri_str!r}
|
| 426 |
raise e
|
| 427 |
|
| 428 |
# Handle other exceptions
|
| 429 |
except Exception as e:
|
| 430 |
-
logger.exception(f"Error reading resource {uri_str!r}
|
| 431 |
if self.mask_error_details:
|
| 432 |
# Mask internal details
|
| 433 |
raise ResourceError(f"Error reading resource {uri_str!r}") from e
|
|
@@ -445,12 +445,12 @@ class ResourceManager:
|
|
| 445 |
return await resource.read()
|
| 446 |
except ResourceError as e:
|
| 447 |
logger.exception(
|
| 448 |
-
f"Error reading resource from template {uri_str!r}
|
| 449 |
)
|
| 450 |
raise e
|
| 451 |
except Exception as e:
|
| 452 |
logger.exception(
|
| 453 |
-
f"Error reading resource from template {uri_str!r}
|
| 454 |
)
|
| 455 |
if self.mask_error_details:
|
| 456 |
raise ResourceError(
|
|
|
|
| 422 |
|
| 423 |
# raise ResourceErrors as-is
|
| 424 |
except ResourceError as e:
|
| 425 |
+
logger.exception(f"Error reading resource {uri_str!r}")
|
| 426 |
raise e
|
| 427 |
|
| 428 |
# Handle other exceptions
|
| 429 |
except Exception as e:
|
| 430 |
+
logger.exception(f"Error reading resource {uri_str!r}")
|
| 431 |
if self.mask_error_details:
|
| 432 |
# Mask internal details
|
| 433 |
raise ResourceError(f"Error reading resource {uri_str!r}") from e
|
|
|
|
| 445 |
return await resource.read()
|
| 446 |
except ResourceError as e:
|
| 447 |
logger.exception(
|
| 448 |
+
f"Error reading resource from template {uri_str!r}"
|
| 449 |
)
|
| 450 |
raise e
|
| 451 |
except Exception as e:
|
| 452 |
logger.exception(
|
| 453 |
+
f"Error reading resource from template {uri_str!r}"
|
| 454 |
)
|
| 455 |
if self.mask_error_details:
|
| 456 |
raise ResourceError(
|
src/fastmcp/tools/tool_manager.py
CHANGED
|
@@ -186,12 +186,12 @@ class ToolManager:
|
|
| 186 |
|
| 187 |
# raise ToolErrors as-is
|
| 188 |
except ToolError as e:
|
| 189 |
-
logger.exception(f"Error calling tool {key!r}
|
| 190 |
raise e
|
| 191 |
|
| 192 |
# Handle other exceptions
|
| 193 |
except Exception as e:
|
| 194 |
-
logger.exception(f"Error calling tool {key!r}
|
| 195 |
if self.mask_error_details:
|
| 196 |
# Mask internal details
|
| 197 |
raise ToolError(f"Error calling tool {key!r}") from e
|
|
|
|
| 186 |
|
| 187 |
# raise ToolErrors as-is
|
| 188 |
except ToolError as e:
|
| 189 |
+
logger.exception(f"Error calling tool {key!r}")
|
| 190 |
raise e
|
| 191 |
|
| 192 |
# Handle other exceptions
|
| 193 |
except Exception as e:
|
| 194 |
+
logger.exception(f"Error calling tool {key!r}")
|
| 195 |
if self.mask_error_details:
|
| 196 |
# Mask internal details
|
| 197 |
raise ToolError(f"Error calling tool {key!r}") from e
|