google / vim-maktaba

Consistent Vimscript
Apache License 2.0
591 stars 42 forks source link

maktaba#syscall fails with E766 when throwing a ShellError for stderr containing a printf format string #223

Closed malcolmr closed 4 years ago

malcolmr commented 4 years ago

https://github.com/google/vim-maktaba/blob/master/autoload/maktaba/syscall.vim#L79 appends stderr to a message string that's (eventually) passed to printf(), but this is invalid if that stderr contains something that looks like a format string.

e.g.

:echo maktaba#syscall#Create('(echo "hello not a format string: %" >&2; exit 1)').Call()
Error detected while processing function maktaba#syscall#Call[3]..<SNR>144_DoSyscallCommon:
line   31:
E605: Exception not caught: ERROR(ShellError): Error running: (echo "hello not a format string: %" >&2; exit 1)^@hello not a format string: ^@

(which is, presumably, correct)

vs.

:echo maktaba#syscall#Create('(echo "hello a format string: %s" >&2; exit 1)').Call()
Error detected while processing function maktaba#syscall#Call[3]..<SNR>144_DoSyscallCommon[31]..maktaba#error#Message[1]..maktaba#error#Exception:
line    5:
E766: Insufficient arguments for printf()
Error detected while processing function maktaba#syscall#Call[3]..<SNR>144_DoSyscallCommon:
line   31:
E605: Exception not caught: -1

The non-error path is fine:

:echo maktaba#syscall#Create('(echo "hello a format string: %s" >&2)').Call()
{'stderr': 'hello a format string: %s
', 'stdout': ''}