@@ -237,42 +237,40 @@ end
237237--- @param cmd string ?
238238--- @param opts table
239239--- @param convert_actions boolean ?
240- --- @return thread , string , table
240+ --- @return thread ? , string , table
241241M .fzf_wrap = function (cmd , opts , convert_actions )
242242 opts = opts or {}
243243 M .set_header (opts )
244244 if convert_actions and type (opts .actions ) == " table" then
245245 opts = M .convert_reload_actions (cmd , opts )
246246 opts = M .convert_exec_silent_actions (opts )
247247 end
248- local _co
249- local wrapped = coroutine.wrap (function ()
248+ -- Do not strt fzf, return the stringified contents and opts onlu
249+ -- used by the "combine" picker to merge inputs
250+ if opts ._start == false then return nil , cmd , opts end
251+ local _co , fn_selected
252+ coroutine.wrap (function ()
250253 _co = coroutine.running ()
251- if type (opts .cb_co ) == " function" then opts .cb_co (_co ) end
252- local selected , exit_code = M .fzf (cmd , opts )
253- -- If aborted (e.g. unhide process kill), do nothing
254- if not tonumber (exit_code ) then return end
255- -- Default fzf exit callback acts upon the selected items
256- local fn_selected = opts .fn_selected or actions .act
257- if not fn_selected then return end
258- -- errors thrown here gets silenced possibly
259- -- due to a coroutine, so catch explicitly
260- local _ , err = pcall (fn_selected , selected , opts )
254+ -- xpcall to get full traceback https://www.lua.org/pil/8.5.html
255+ local _ , err = xpcall (function ()
256+ if type (opts .cb_co ) == " function" then opts .cb_co (_co ) end
257+ local selected , exit_code = M .fzf (cmd , opts )
258+ -- If aborted (e.g. unhide process kill), do nothing
259+ if not tonumber (exit_code ) then return end
260+ -- Default fzf exit callback acts upon the selected items
261+ fn_selected = opts .fn_selected or actions .act
262+ if not fn_selected then return end
263+ -- errors thrown here gets silenced possibly
264+ -- due to a coroutine, so catch explicitly
265+ fn_selected (selected , opts )
266+ end , debug.traceback )
261267 -- ignore existing swap file error, the choices dialog will still be
262268 -- displayed to user to make a selection once fzf-lua exits (#1011)
263269 if err then
264- if err :match (" Vim%(edit%):E325" ) then return end
265- utils .error (" fn_selected threw an error: " .. debug.traceback (_co , err , 1 ))
266- end
267- end )
268- -- Do not strt fzf, return the stringified contents and opts onlu
269- -- used by the "combine" picker to merge inputs
270- if opts ._start ~= false then
271- local ok , err = pcall (wrapped )
272- if not ok and err then
273- error (debug.traceback (_co , err , 1 ))
270+ if fn_selected and err :match (" Vim%(edit%):E325" ) then return end
271+ utils .error (" fn_selected threw an error: " .. err )
274272 end
275- end
273+ end )()
276274 return _co , cmd , opts
277275end
278276
0 commit comments