Skip to content

Commit f913e6b

Browse files
phanenibhagwan
authored andcommitted
fix: ui freeze when action error
regression of a234df1
1 parent df8c2ca commit f913e6b

4 files changed

Lines changed: 105 additions & 4 deletions

File tree

lua/fzf-lua/shell.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,17 @@ M.stringify = function(contents, opts, fzf_field_index)
426426
return on_write(data, cb)
427427
end
428428

429-
if type(contents) == "table" then
430-
vim.tbl_map(function(x) on_write_nl(x) end, contents)
429+
local ok, err = pcall(function()
430+
if type(contents) == "table" then
431+
vim.tbl_map(function(x) on_write_nl(x) end, contents)
432+
on_finish()
433+
elseif type(contents) == "function" then
434+
contents(on_write_nl, on_write, unpack(args))
435+
end
436+
end)
437+
if not ok and err then
431438
on_finish()
432-
elseif type(contents) == "function" then
433-
contents(on_write_nl, on_write, unpack(args))
439+
error(err)
434440
end
435441
end
436442
end, fzf_field_index or "", opts.debug)

tests/actions_spec.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---@diagnostic disable: unused-local, unused-function
2+
local MiniTest = require("mini.test")
3+
local helpers = require("fzf-lua.test.helpers")
4+
local child = helpers.new_child_neovim()
5+
local expect, eq = helpers.expect, helpers.expect.equality
6+
local new_set = MiniTest.new_set
7+
8+
---@format disable-next
9+
local reload = function(config) child.unload(); child.setup(config) end
10+
local sleep = function(ms) helpers.sleep(ms, child) end
11+
local exec_lua = child.lua
12+
--stylua: ignore end
13+
14+
local T = helpers.new_set_with_child(child)
15+
16+
T["actions"] = new_set({ n_retry = not helpers.IS_LINUX() and 5 or nil })
17+
18+
T["actions"]["ui don't freeze on error"] = function()
19+
-- reload({ "hide" })
20+
exec_lua(
21+
[[FzfLua.fzf_exec({ "aaa", "bbb" }, {
22+
actions = { enter = { fn = error, exec_silent = true } },
23+
})]])
24+
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
25+
child.type_keys("<cr>")
26+
child.type_keys("ui should not freeze on action error")
27+
vim.uv.sleep(100 * (not helpers.IS_LINUX() and 5 or 1))
28+
child.expect_screen_lines({ redraw = true })
29+
30+
exec_lua([[FzfLua.fzf_exec(function(cb) cb(1) cb(2) error("eff") end)]])
31+
child.wait_until(function() return child.lua_get([[_G._fzf_load_called]]) == true end)
32+
child.type_keys("ui should not freeze on content error")
33+
vim.uv.sleep(100 * (not helpers.IS_LINUX() and 5 or 1))
34+
child.expect_screen_lines({ ignore_text = { 28 } })
35+
end
36+
37+
return T
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────────────────────────────────────╮
5+
04|~ │> ui should not freeze on action error 0/2 │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │ │
8+
07|~ │ │
9+
08|~ │ │
10+
09|~ │ │
11+
10|~ │ │
12+
11|~ │ │
13+
12|~ │ │
14+
13|~ │ │
15+
14|~ │ │
16+
15|~ │ │
17+
16|~ │ │
18+
17|~ │ │
19+
18|~ │ │
20+
19|~ │ │
21+
20|~ │ │
22+
21|~ │ │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,3 All
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--|---------|---------|---------|---------|---------|---------|----
2+
01|
3+
02|~
4+
03|~ ╭─────────────────────────────────────────────────╮
5+
04|~ │> ui should not freeze on content error 0/2 │
6+
05|~ │──────────────────────────────────────────────── │
7+
06|~ │ │
8+
07|~ │ │
9+
08|~ │ │
10+
09|~ │ │
11+
10|~ │ │
12+
11|~ │ │
13+
12|~ │ │
14+
13|~ │ │
15+
14|~ │ │
16+
15|~ │ │
17+
16|~ │ │
18+
17|~ │ │
19+
18|~ │ │
20+
19|~ │ │
21+
20|~ │ │
22+
21|~ │ │
23+
22|~ ╰─────────────────────────────────────────────────╯
24+
23|~
25+
24|[No Name] 0,0-1 All
26+
25|
27+
26|
28+
27|
29+
28|-- TERMINAL -- 1,0-38 All

0 commit comments

Comments
 (0)