Skip to content

Commit 1a2004f

Browse files
committed
fix: add debug logging for close failures and use logging.exception
- Add debug logging when document.close() fails in close_document/reload_document - Use logger.exception() instead of logger.error() for better tracebacks in shutdown
1 parent 5669450 commit 1a2004f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

‎docx_editor_mcp/server.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def shutdown(self) -> None:
2525
try:
2626
cached_doc.document.save()
2727
logger.info(f"Saved dirty document: {cached_doc.path}")
28-
except Exception as e:
29-
logger.error(f"Failed to save {cached_doc.path}: {e}")
28+
except Exception:
29+
logger.exception("Failed to save %s", cached_doc.path)
3030
# Continue with other documents (best-effort)
3131

3232
# Clear cache

‎docx_editor_mcp/tools.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""MCP Tools for docx_editor operations."""
22

3+
import logging
34
import os
45
from typing import Any, cast
56

67
from docx_editor import Document
8+
9+
logger = logging.getLogger(__name__)
710
from docx_editor.exceptions import TextNotFoundError
811

912
from .cache import CachedDocument, normalize_path
@@ -149,7 +152,7 @@ def close_document(server: DocxMCPServer, path: str) -> dict[str, Any]:
149152
try:
150153
cached.document.close()
151154
except Exception:
152-
pass # Best effort
155+
logger.debug("Failed to close document: %s", path)
153156

154157
server.cache.remove(path)
155158
return result
@@ -178,7 +181,7 @@ def reload_document(server: DocxMCPServer, path: str) -> dict[str, Any]:
178181
try:
179182
cached.document.close()
180183
except Exception:
181-
pass
184+
logger.debug("Failed to close document during reload: %s", path)
182185

183186
# Remove from cache
184187
server.cache.remove(path)

0 commit comments

Comments
 (0)