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
6 changes: 5 additions & 1 deletion entangled/commands/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .sync import run_sync
from .main import main
from ..errors.user import UserError

import watchfiles

Expand Down Expand Up @@ -38,7 +39,10 @@ def stop() -> bool:

for changes in watchfiles.watch(dirs, stop_event=_stop_event, watch_filter=watch_filter):
log.debug(changes)
run_sync()
try:
run_sync()
except UserError as e:
logger().error(e, exc_info=False)


@main.command()
Expand Down
64 changes: 64 additions & 0 deletions test/commands/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,70 @@ def wait_for_stat_diff(md_stat, filename, timeout=5):
return False


NO_CRASH_MAIN_MD1 = """
---
entangled:
version: "2.4"
style: "basic"
---

We have a missing reference here.

```python
#| file: test.py
<<test>>
```
""".lstrip()

NO_CRASH_MAIN_MD2 = """
---
entangled:
version: "2.4"
style: "basic"
---

Now it is fixed.

```python
#| file: test.py
<<test>>
```

```python
#| id: test
print("Hello, World")
```
""".lstrip()

@pytest.mark.timeout(10)
def test_no_crash(tmp_path: Path):
"""
Test for issue #95; The watch process would crash on a UserError.
With the new behaviour the process should not do anything, print
a message, but keep running.
"""
with chdir(tmp_path):
configure(debug=True)
stop = threading.Event()
start = threading.Event()
t = threading.Thread(target=_watch, args=(stop, start))
try:
t.start()
# Wait for watch to boot up
start.wait()

Path("main.md").write_text(NO_CRASH_MAIN_MD1)
time.sleep(0.1)
assert not Path("test.py").exists()
Path("main.md").write_text(NO_CRASH_MAIN_MD2)
assert wait_for_file("test.py")

finally:
stop.set()
t.join()
time.sleep(0.1)


@pytest.mark.timeout(10)
def test_daemon(tmp_path: Path):
with chdir(tmp_path):
Expand Down
Loading
Loading