Skip to content

Commit a96c737

Browse files
committed
feat[telemetry]: enhance error message sanitization to preserve filenames and improve path handling
1 parent 380fc6e commit a96c737

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/golf/core/telemetry.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,14 @@ def _sanitize_error_message(message: str) -> str:
412412
"""Sanitize error messages to remove sensitive information."""
413413
import re
414414

415-
# Remove file paths (both Unix and Windows style)
416-
message = re.sub(r"[/\\][^\s]*[/\\][^\s]*", "[PATH]", message)
415+
# Remove file paths but preserve filenames
416+
# Match paths with directories and capture the filename
417+
# Unix style: /path/to/file.py -> file.py
418+
message = re.sub(r"(/[^/\s]+)+/([^/\s]+)", r"\2", message)
419+
# Windows style: C:\path\to\file.py -> file.py
420+
message = re.sub(r"([A-Za-z]:\\[^\\]+\\)+([^\\]+)", r"\2", message)
421+
# Remaining absolute paths without filename
422+
message = re.sub(r"[/\\][^\s]*[/\\]", "[PATH]/", message)
417423

418424
# Remove potential API keys or tokens (common patterns)
419425
# Generic API keys (20+ alphanumeric with underscores/hyphens)

0 commit comments

Comments
 (0)