Skip to content

Commit

Permalink
Improve error reporting in xolox#misc#os#exec()
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 19, 2013
1 parent f7ed989 commit ef20062
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion autoload/xolox/misc/compat.vim
Expand Up @@ -7,7 +7,7 @@
" scripts breaks backwards compatibility. This enables my Vim plug-ins to fail
" early when they detect an incompatible version, instead of breaking at the
" worst possible moments :-).
let g:xolox#misc#compat#version = 4
let g:xolox#misc#compat#version = 5

" Remember the directory where the miscellaneous scripts are loaded from
" so the user knows which plug-in to update if incompatibilities arise.
Expand Down
24 changes: 17 additions & 7 deletions autoload/xolox/misc/os.vim
Expand Up @@ -87,19 +87,29 @@ function! xolox#misc#os#exec(options) " {{{1

endif

let result = {}
" Return the results as a dictionary with one or more key/value pairs.
let result = {'command': cmd}
if !async
let result['exit_code'] = exit_code
let result['stdout'] = s:readfile(tempout)
let result['stderr'] = s:readfile(temperr)
" If we just executed a synchronous command and the caller didn't
" specifically ask us *not* to check the exit code of the external
" command, we'll do so now.
if get(a:options, 'check', 1) && exit_code != 0
let msg = "os.vim %s: External command failed with exit code %d: %s"
throw printf(msg, g:xolox#misc#os#version, result['exit_code'], result['command'])
" Prepare an error message with enough details so the user can investigate.
let msg = printf("os.vim %s: External command failed with exit code %d!", g:xolox#misc#os#version, result['exit_code'])
let msg .= printf("\nCommand line: %s", result['command'])
" If the external command reported an error, we'll include it in our message.
if !empty(result['stderr'])
" This is where we would normally expect to find an error message.
let msg .= printf("\nOutput on standard output stream:\n%s", join(result['stderr'], "\n"))
elseif !empty(result['stdout'])
" Exuberant Ctags on Windows XP reports errors on standard output :-x.
let msg .= printf("\nOutput on standard error stream:\n%s", join(result['stdout'], "\n"))
endif
throw msg
endif
" Return the results as a dictionary with three key/value pairs.
let result['exit_code'] = exit_code
let result['stdout'] = s:readfile(tempout)
let result['stderr'] = s:readfile(temperr)
endif
return result

Expand Down

0 comments on commit ef20062

Please sign in to comment.