Skip to content

Commit 097cf10

Browse files
committed
Fixes #61: Catch yapf errors instead of overwriting file
1 parent 74dbd84 commit 097cf10

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

autoload/codefmt.vim

+9-4
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,17 @@ function! codefmt#GetYAPFFormatter() abort
437437
let l:cmd = [l:executable, '--lines=' . a:startline . '-' . a:endline]
438438
let l:input = join(l:lines, "\n")
439439

440-
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call(0)
441-
let l:formatted = split(l:result.stdout, "\n")
440+
try
441+
let l:result = maktaba#syscall#Create(l:cmd).WithStdin(l:input).Call()
442+
let l:formatted = split(l:result.stdout, "\n")
443+
444+
let l:full_formatted = l:formatted
442445

443-
let l:full_formatted = l:formatted
446+
call maktaba#buffer#Overwrite(1, line('$'), l:full_formatted)
447+
catch /ERROR(ShellError):/
448+
call maktaba#error#Shout('Error formatting file: %s', v:exception)
449+
endtry
444450

445-
call maktaba#buffer#Overwrite(1, line('$'), l:full_formatted)
446451
endfunction
447452

448453
return l:formatter

0 commit comments

Comments
 (0)