Skip to content

Commit f4e4d03

Browse files
committed
Handle stderr callback
This can help with debugging.
1 parent 5e90d22 commit f4e4d03

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

autoload/tpipeline.vim

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ func tpipeline#initialize()
142142
augroup END
143143
endfunc
144144

145+
func tpipeline#on_stderr(chan_id, data, name)
146+
let s:elines[-1] .= a:data[0]
147+
call extend(s:elines, a:data[1:])
148+
while len(s:elines) > 1
149+
let line = remove(s:elines, 0)
150+
call tpipeline#debug#log_err(line)
151+
endwhile
152+
endfunc
153+
154+
func tpipeline#err_cb(channel, msg)
155+
call tpipeline#debug#log_err(a:msg)
156+
endfunc
157+
145158
func tpipeline#on_exit(job, code, t)
146159
call tpipeline#state#freeze()
147160
let s:exit_code = a:code
@@ -183,11 +196,12 @@ func tpipeline#fork_job()
183196

184197
let command = ['bash', '-c', script]
185198
if s:is_nvim
186-
let options = #{on_exit: function('tpipeline#on_exit')}
199+
let s:elines = ['']
200+
let options = #{on_stderr: function('tpipeline#on_stderr'), on_exit: function('tpipeline#on_exit')}
187201
let s:job = jobstart(command, options)
188202
let s:channel = s:job
189203
else
190-
let options = #{noblock: 1, exit_cb: function('tpipeline#exit_cb')}
204+
let options = #{noblock: 1, err_cb: function('tpipeline#err_cb'), exit_cb: function('tpipeline#exit_cb')}
191205
let s:job = job_start(command, options)
192206
let s:channel = job_getchannel(s:job)
193207
endif

autoload/tpipeline/debug.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
func tpipeline#debug#init()
2+
let s:stderr = []
23
let s:tpipeline_filepath = tpipeline#get_filepath()
34
let s:tpipeline_right_filepath = s:tpipeline_filepath . '-R'
45
endfunc
@@ -20,7 +21,7 @@ func tpipeline#debug#info()
2021
let tmux = systemlist("tmux -V")[-1]
2122
let jobstate = tpipeline#job_state()
2223
let os = tpipeline#debug#os()
23-
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), job_state: jobstate, os: os}
24+
let result = #{left: left, right: right, tmux: tmux, plugin_version: tpipeline#version#string(), job_state: jobstate, job_errors: s:stderr, os: os}
2425

2526
if has('nvim')
2627
let stl = g:tpipeline_statusline
@@ -45,4 +46,8 @@ func tpipeline#debug#info()
4546
return result
4647
endfunc
4748

49+
func tpipeline#debug#log_err(line)
50+
call add(s:stderr, a:line)
51+
endfunc
52+
4853
call tpipeline#debug#init()

lua/tpipeline/health.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ M.check = function()
1616
else
1717
vim.health.report_error(string.format("Background job is not running: %s", info.job_state))
1818
end
19+
20+
if next(info.job_errors) == nil then
21+
vim.health.report_ok("No job errors reported")
22+
else
23+
vim.health.report_warn("Job reported errors", info.job_errors)
24+
end
1925
end
2026

2127
return M

tests/test_general.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func Test_job_runs()
3434
let job = tpipeline#debug#info()
3535
" background job is still running
3636
call assert_match("^run", job.job_state)
37+
" no errors
38+
call assert_true(job.job_errors->empty(), job.job_errors)
3739
endfunc
3840

3941
func Strip_hl(s)

0 commit comments

Comments
 (0)