From 719369b52eaf59f3cbdace7fd274f8567ddae408 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sun, 6 Oct 2019 13:33:48 -0700 Subject: [PATCH 1/2] util: catch exceptions trying to execute system commands --- autoload/go/util.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/go/util.vim b/autoload/go/util.vim index 9e4a9bfd5b..30bb82714e 100644 --- a/autoload/go/util.vim +++ b/autoload/go/util.vim @@ -198,7 +198,13 @@ function! go#util#Exec(cmd, ...) abort " Finally execute the command using the full, resolved path. Do not pass the " unmodified command as the correct program might not exist in $PATH. - return call('s:exec', [[l:bin] + a:cmd[1:]] + a:000) + try + return call('s:exec', [[l:bin] + a:cmd[1:]] + a:000) + catch + " TODO(bc): return v:exception as the output here or write it with + " go#util#EchoError? + return ['', 1] + endtry endfunction function! go#util#ExecInDir(cmd, ...) abort From db8389cbda24088d4b85f0288d0458aa862da840 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Mon, 7 Oct 2019 19:43:24 -0700 Subject: [PATCH 2/2] util: provide some useful output strings --- autoload/go/util.vim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/autoload/go/util.vim b/autoload/go/util.vim index 30bb82714e..689cce08ff 100644 --- a/autoload/go/util.vim +++ b/autoload/go/util.vim @@ -193,7 +193,7 @@ function! go#util#Exec(cmd, ...) abort " CheckBinPath will show a warning for us. let l:bin = go#path#CheckBinPath(l:bin) if empty(l:bin) - return ['', 1] + return ['command not found', 1] endif " Finally execute the command using the full, resolved path. Do not pass the @@ -201,15 +201,13 @@ function! go#util#Exec(cmd, ...) abort try return call('s:exec', [[l:bin] + a:cmd[1:]] + a:000) catch - " TODO(bc): return v:exception as the output here or write it with - " go#util#EchoError? - return ['', 1] + return [v:exception, 1] endtry endfunction function! go#util#ExecInDir(cmd, ...) abort if !isdirectory(expand("%:p:h")) - return ['', 1] + return ['not a directory', 1] endif let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '