Skip to content

Commit 744e0f3

Browse files
committed
Handle exceptions from async tasks
1 parent f3bb0b7 commit 744e0f3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lua/clojure-test/api/init.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ local function run_tests_and_update_state(tests)
1717
M.state.last_run = run_api.run_tests(tests)
1818
end
1919

20+
local function with_exceptions(fn)
21+
nio.run(fn, function(success, stacktrace)
22+
if not success then
23+
vim.notify(stacktrace, vim.log.levels.ERROR)
24+
end
25+
end)
26+
end
27+
2028
function M.run_all_tests()
2129
nio.run(function()
2230
local tests = tests_api.get_all_tests()
@@ -28,7 +36,7 @@ function M.run_all_tests()
2836
end
2937

3038
function M.run_tests()
31-
nio.run(function()
39+
with_exceptions(function()
3240
local current_test = location.get_test_at_cursor()
3341

3442
local tests
@@ -47,7 +55,7 @@ function M.run_tests()
4755
end
4856

4957
function M.run_tests_in_ns()
50-
nio.run(function()
58+
with_exceptions(function()
5159
local namespaces
5260
local current_namespace = location.get_current_namespace()
5361
local test_namespaces = tests_api.get_test_namespaces()
@@ -74,7 +82,7 @@ function M.run_tests_in_ns()
7482
end
7583

7684
function M.rerun_previous()
77-
nio.run(function()
85+
with_exceptions(function()
7886
if not M.state.previous then
7987
return
8088
end
@@ -83,7 +91,7 @@ function M.rerun_previous()
8391
end
8492

8593
function M.rerun_failed()
86-
nio.run(function()
94+
with_exceptions(function()
8795
local failed = {}
8896
for test, report in pairs(M.state.last_run) do
8997
if report.status == "failed" then
@@ -101,20 +109,20 @@ function M.rerun_failed()
101109
end
102110

103111
function M.open_last_report()
104-
if not M.state.last_run then
112+
if not M.state.last_run then
105113
return
106114
end
107115
run_api.open_reports(M.state.last_run)
108116
end
109117

110118
function M.load_tests()
111-
nio.run(function()
119+
with_exceptions(function()
112120
tests_api.load_tests()
113121
end)
114122
end
115123

116124
function M.analyze_exception(sym)
117-
nio.run(function()
125+
with_exceptions(function()
118126
exceptions_api.render_exception(sym)
119127
end)
120128
end

0 commit comments

Comments
 (0)