Change error reporting method
As suggested by @vheon: https://github.com/junegunn/vim-plug/pull/40#issuecomment-50278543
This commit is contained in:
parent
8738341ad0
commit
d690f8d576
54
plug.vim
54
plug.vim
|
@ -86,21 +86,18 @@ function! plug#begin(...)
|
||||||
elseif !empty(&rtp)
|
elseif !empty(&rtp)
|
||||||
let home = s:path(split(&rtp, ',')[0]) . '/plugged'
|
let home = s:path(split(&rtp, ',')[0]) . '/plugged'
|
||||||
else
|
else
|
||||||
echoerr "Unable to determine plug home. Try calling plug#begin() with a path argument."
|
return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.')
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !isdirectory(home)
|
if !isdirectory(home)
|
||||||
try
|
try
|
||||||
call mkdir(home, 'p')
|
call mkdir(home, 'p')
|
||||||
catch
|
catch
|
||||||
echoerr 'Invalid plug directory: '. home
|
return s:err('Invalid plug directory: '. home)
|
||||||
return 0
|
|
||||||
endtry
|
endtry
|
||||||
endif
|
endif
|
||||||
if !executable('git')
|
if !executable('git')
|
||||||
echoerr "`git' executable not found. vim-plug requires git."
|
return s:err('`git` executable not found. vim-plug requires git.')
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let g:plug_home = home
|
let g:plug_home = home
|
||||||
|
@ -125,8 +122,7 @@ endfunction
|
||||||
|
|
||||||
function! plug#end()
|
function! plug#end()
|
||||||
if !exists('g:plugs')
|
if !exists('g:plugs')
|
||||||
echoerr 'Call plug#begin() first'
|
return s:err('Call plug#begin() first')
|
||||||
return
|
|
||||||
endif
|
endif
|
||||||
let keys = keys(g:plugs)
|
let keys = keys(g:plugs)
|
||||||
let plugfiles = s:find_plugfiles()
|
let plugfiles = s:find_plugfiles()
|
||||||
|
@ -226,6 +222,13 @@ else
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! s:err(msg)
|
||||||
|
echohl ErrorMsg
|
||||||
|
echom a:msg
|
||||||
|
echohl None
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:esc(path)
|
function! s:esc(path)
|
||||||
return substitute(a:path, ' ', '\\ ', 'g')
|
return substitute(a:path, ' ', '\\ ', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -293,11 +296,9 @@ endfunction
|
||||||
|
|
||||||
function! s:add(force, repo, ...)
|
function! s:add(force, repo, ...)
|
||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
echoerr "Invalid number of arguments (1..2)"
|
return s:err('Invalid number of arguments (1..2)')
|
||||||
return
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let exception = ''
|
|
||||||
try
|
try
|
||||||
let repo = s:trim_trailing_slashes(a:repo)
|
let repo = s:trim_trailing_slashes(a:repo)
|
||||||
let name = s:extract_name(repo)
|
let name = s:extract_name(repo)
|
||||||
|
@ -315,27 +316,22 @@ function! s:add(force, repo, ...)
|
||||||
let g:plugs[name] = spec
|
let g:plugs[name] = spec
|
||||||
let g:plugs_order += [name]
|
let g:plugs_order += [name]
|
||||||
catch
|
catch
|
||||||
let exception = v:exception
|
return s:err(v:exception)
|
||||||
endtry
|
endtry
|
||||||
if !empty(exception)
|
|
||||||
echoerr exception
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_options(arg)
|
function! s:parse_options(arg)
|
||||||
let opts = { 'branch': 'master', 'frozen': 0, 'local': 0 }
|
let opts = { 'branch': 'master', 'frozen': 0, 'local': 0 }
|
||||||
if !empty(a:arg)
|
let type = type(a:arg)
|
||||||
let type = type(a:arg)
|
if type == s:TYPE.string
|
||||||
if type == s:TYPE.string
|
let opts.branch = a:arg
|
||||||
let opts.branch = a:arg
|
elseif type == s:TYPE.dict
|
||||||
elseif type == s:TYPE.dict
|
call extend(opts, a:arg)
|
||||||
call extend(opts, a:arg)
|
if has_key(opts, 'tag')
|
||||||
if has_key(opts, 'tag')
|
let opts.branch = remove(opts, 'tag')
|
||||||
let opts.branch = remove(opts, 'tag')
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
throw "Invalid argument type (expected: string or dictionary)"
|
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
throw 'Invalid argument type (expected: string or dictionary)'
|
||||||
endif
|
endif
|
||||||
return opts
|
return opts
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -1068,8 +1064,7 @@ function! s:upgrade()
|
||||||
echo "Downloaded ". s:plug_source
|
echo "Downloaded ". s:plug_source
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
echoerr "Error upgrading vim-plug"
|
return s:err('Error upgrading vim-plug')
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
elseif has('ruby')
|
elseif has('ruby')
|
||||||
echo "Downloading ". s:plug_source
|
echo "Downloading ". s:plug_source
|
||||||
|
@ -1089,8 +1084,7 @@ EOF
|
||||||
echo "Downloaded ". s:plug_source
|
echo "Downloaded ". s:plug_source
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
echoerr "curl executable or ruby support not found"
|
return s:err('curl executable or ruby support not found')
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,10 @@ Execute (Initialize test environment):
|
||||||
let $MYVIMRC = vimrc
|
let $MYVIMRC = vimrc
|
||||||
|
|
||||||
Execute (plug#end() before plug#begin() should fail):
|
Execute (plug#end() before plug#begin() should fail):
|
||||||
try
|
redir => out
|
||||||
call plug#end()
|
AssertEqual 0, plug#end()
|
||||||
Assert 0, 'should not reach here'
|
redir END
|
||||||
catch
|
Assert stridx(out, 'Call plug#begin() first') >= 0
|
||||||
Assert stridx(v:exception, 'Call plug#begin() first') >= 0
|
|
||||||
endtry
|
|
||||||
|
|
||||||
Execute (plug#begin() without path argument):
|
Execute (plug#begin() without path argument):
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
|
@ -54,12 +52,10 @@ Execute (plug#begin() without path argument):
|
||||||
Execute (plug#begin() without path argument with empty &rtp):
|
Execute (plug#begin() without path argument with empty &rtp):
|
||||||
let save_rtp = &rtp
|
let save_rtp = &rtp
|
||||||
set rtp=
|
set rtp=
|
||||||
try
|
redir => out
|
||||||
call plug#begin()
|
AssertEqual 0, plug#begin()
|
||||||
Assert 0, 'should not reach here'
|
redir END
|
||||||
catch
|
Assert stridx(out, 'Unable to determine plug home') >= 0
|
||||||
Assert stridx(v:exception, 'Unable to determine plug home') >= 0, 'Got: '.v:exception
|
|
||||||
endtry
|
|
||||||
let &rtp = save_rtp
|
let &rtp = save_rtp
|
||||||
|
|
||||||
Execute (plug#begin(path)):
|
Execute (plug#begin(path)):
|
||||||
|
@ -671,7 +667,7 @@ Execute (Cleanup):
|
||||||
unlet g:plugs
|
unlet g:plugs
|
||||||
unlet g:plug_home
|
unlet g:plug_home
|
||||||
unlet g:vimrc_reloaded
|
unlet g:vimrc_reloaded
|
||||||
unlet temp_plugged vader plug basertp save_rtp repo lnum fzf
|
unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out
|
||||||
delf PlugStatusSorted
|
delf PlugStatusSorted
|
||||||
delf AssertExpect
|
delf AssertExpect
|
||||||
delf PlugUpdated
|
delf PlugUpdated
|
||||||
|
|
Loading…
Reference in New Issue
Block a user