Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/echo/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _run_command(self, event_path):
else:
console.print(f"[red]✖ Command failed with exit code {process.returncode}.[/red]")
except Exception as e:
console.print(f"[bold red]Error executing command: {e}[/bold red]")
console.print(f"[bold red]Error executing command: {escape(str(e))}[/bold red]")

def _is_ignored_impl(self, path: str) -> bool:
if path.startswith(self._abs_base_path):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_markup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time
from echo.watcher import CommandRunnerHandler
import subprocess

from unittest.mock import MagicMock

def test_rich_markup_crash_escaping():
Expand All @@ -24,3 +26,23 @@ def test_rich_markup_crash_escaping():
if handler.current_process:
handler.current_process.terminate()
handler.current_process.wait()


def test_rich_error_crash():
handler = CommandRunnerHandler("echo test")

class MockException(Exception):
def __str__(self):
return "File not found: [missing.py]"

original_popen = subprocess.Popen

def fake_popen(*args, **kwargs):
raise MockException()

subprocess.Popen = fake_popen
try:
# this should crash rich with MarkupError if not escaped
handler._run_command("test.txt")
finally:
subprocess.Popen = original_popen
Loading