Skip to content

Commit 8c0bd4d

Browse files
authored
Merge pull request #97 from entangled/95-catch-missing-ref-excn
95 catch missing ref excn
2 parents 42d63f5 + 08cca75 commit 8c0bd4d

3 files changed

Lines changed: 537 additions & 429 deletions

File tree

entangled/commands/watch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .sync import run_sync
88
from .main import main
9+
from ..errors.user import UserError
910

1011
import watchfiles
1112

@@ -38,7 +39,10 @@ def stop() -> bool:
3839

3940
for changes in watchfiles.watch(dirs, stop_event=_stop_event, watch_filter=watch_filter):
4041
log.debug(changes)
41-
run_sync()
42+
try:
43+
run_sync()
44+
except UserError as e:
45+
logger().error(e, exc_info=False)
4246

4347

4448
@main.command()

test/commands/test_daemon.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,70 @@ def wait_for_stat_diff(md_stat, filename, timeout=5):
3838
return False
3939

4040

41+
NO_CRASH_MAIN_MD1 = """
42+
---
43+
entangled:
44+
version: "2.4"
45+
style: "basic"
46+
---
47+
48+
We have a missing reference here.
49+
50+
```python
51+
#| file: test.py
52+
<<test>>
53+
```
54+
""".lstrip()
55+
56+
NO_CRASH_MAIN_MD2 = """
57+
---
58+
entangled:
59+
version: "2.4"
60+
style: "basic"
61+
---
62+
63+
Now it is fixed.
64+
65+
```python
66+
#| file: test.py
67+
<<test>>
68+
```
69+
70+
```python
71+
#| id: test
72+
print("Hello, World")
73+
```
74+
""".lstrip()
75+
76+
@pytest.mark.timeout(10)
77+
def test_no_crash(tmp_path: Path):
78+
"""
79+
Test for issue #95; The watch process would crash on a UserError.
80+
With the new behaviour the process should not do anything, print
81+
a message, but keep running.
82+
"""
83+
with chdir(tmp_path):
84+
configure(debug=True)
85+
stop = threading.Event()
86+
start = threading.Event()
87+
t = threading.Thread(target=_watch, args=(stop, start))
88+
try:
89+
t.start()
90+
# Wait for watch to boot up
91+
start.wait()
92+
93+
Path("main.md").write_text(NO_CRASH_MAIN_MD1)
94+
time.sleep(0.1)
95+
assert not Path("test.py").exists()
96+
Path("main.md").write_text(NO_CRASH_MAIN_MD2)
97+
assert wait_for_file("test.py")
98+
99+
finally:
100+
stop.set()
101+
t.join()
102+
time.sleep(0.1)
103+
104+
41105
@pytest.mark.timeout(10)
42106
def test_daemon(tmp_path: Path):
43107
with chdir(tmp_path):

0 commit comments

Comments
 (0)