Skip to content

Commit

Permalink
fixing error propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Badragan committed Sep 30, 2024
1 parent 8a03bd4 commit e68765e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lua/grug-far/actions/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ local function search(params)
else
if errorMessage and #errorMessage > 0 then
resultsList.appendWarning(buf, context, errorMessage)
state.actionMessage = ' warnings, see end of buffer!'

local lastline = vim.api.nvim_buf_line_count(buf)
local winheight = vim.api.nvim_win_get_height(vim.fn.bufwinid(buf))
state.actionMessage = lastline < winheight and ' warnings!'
or ' warnings, see end of buffer!'
end
resultsList.highlight(buf, context)
end
Expand Down
13 changes: 7 additions & 6 deletions lua/grug-far/engine/fetchCommandOutput.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local function fetchCommandOutput(params)
local stdout = uv.new_pipe()
local stderr = uv.new_pipe()
local lastLine = ''
local hadStdout = false

local handle
handle = uv.spawn(params.cmd_path, {
Expand All @@ -46,14 +47,12 @@ local function fetchCommandOutput(params)
utils.closeHandle(stderr)
utils.closeHandle(handle)

local isSuccess = code == 0
if not isSuccess then
-- finish immediately if error, so no more result updates are sent out to the consumer
finished = true
end

vim.schedule(function()
finished = true
-- note: when no stdout, we report errors with a message as warnings (status = success) since
-- for example ripgrep can generate errors only for a particular file (like permission denied
-- but everything else succeeded
local isSuccess = code == 0 or (hadStdout and errorMessage and #errorMessage > 0)
on_finish(isSuccess and 'success' or 'error', errorMessage)
end)
end)
Expand Down Expand Up @@ -90,6 +89,8 @@ local function fetchCommandOutput(params)
end

if data then
hadStdout = true

-- large outputs can cause the last line to be truncated
-- save it and prepend to next chunk
local chunkData = lastLine .. data
Expand Down
2 changes: 1 addition & 1 deletion lua/grug-far/render/resultsList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function M.appendWarning(buf, context, warning)
end
local lastline = vim.api.nvim_buf_line_count(buf)

local warn_lines = vim.split('\n\n' .. warning, '\n')
local warn_lines = vim.split(warning, '\n')
setBufLines(buf, lastline, lastline, false, warn_lines)

for i = lastline, lastline + #warn_lines - 1 do
Expand Down

0 comments on commit e68765e

Please sign in to comment.