:Plug throws error for invalid option (#961)
":Plug" performs a quick type check for most options so that the user can check which plugin has invalid configuration on startup. This does not prevent errors, resulting from modiying "g:plugs" after running "plug#end()". Plugin repo is added to the error message for convenience. Most users should expect no noticeable difference in startup time. Close: #930 Related: #936
This commit is contained in:
parent
71c41fccf5
commit
6583b99032
2 changed files with 49 additions and 2 deletions
24
plug.vim
24
plug.vim
|
@ -632,17 +632,39 @@ function! plug#(repo, ...)
|
||||||
let g:plugs[name] = spec
|
let g:plugs[name] = spec
|
||||||
let s:loaded[name] = get(s:loaded, name, 0)
|
let s:loaded[name] = get(s:loaded, name, 0)
|
||||||
catch
|
catch
|
||||||
return s:err(v:exception)
|
return s:err(repo . ' ' . v:exception)
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:parse_options(arg)
|
function! s:parse_options(arg)
|
||||||
let opts = copy(s:base_spec)
|
let opts = copy(s:base_spec)
|
||||||
let type = type(a:arg)
|
let type = type(a:arg)
|
||||||
|
let opt_errfmt = 'Invalid argument for "%s" option of :Plug (expected: %s)'
|
||||||
if type == s:TYPE.string
|
if type == s:TYPE.string
|
||||||
|
if empty(a:arg)
|
||||||
|
throw printf(opt_errfmt, 'tag', 'string')
|
||||||
|
endif
|
||||||
let opts.tag = a:arg
|
let opts.tag = a:arg
|
||||||
elseif type == s:TYPE.dict
|
elseif type == s:TYPE.dict
|
||||||
call extend(opts, a:arg)
|
call extend(opts, a:arg)
|
||||||
|
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
|
||||||
|
if has_key(opts, opt)
|
||||||
|
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
|
||||||
|
throw printf(opt_errfmt, opt, 'string')
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
for opt in ['on', 'for']
|
||||||
|
if has_key(opts, opt)
|
||||||
|
\ && type(opts[opt]) != s:TYPE.list
|
||||||
|
\ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt]))
|
||||||
|
throw printf(opt_errfmt, opt, 'string or list')
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if has_key(opts, 'do')
|
||||||
|
\ && type(opts.do) != s:TYPE.funcref
|
||||||
|
\ && (type(opts.do) != s:TYPE.string || empty(opts.do))
|
||||||
|
throw printf(opt_errfmt, 'do', 'string or funcref')
|
||||||
|
endif
|
||||||
if has_key(opts, 'dir')
|
if has_key(opts, 'dir')
|
||||||
let opts.dir = s:dirpath(s:plug_expand(opts.dir))
|
let opts.dir = s:dirpath(s:plug_expand(opts.dir))
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -49,11 +49,19 @@ Execute (Test Plug command):
|
||||||
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
|
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
|
||||||
|
|
||||||
^ Git repo with tag (DEPRECATED. USE TAG OPTION)
|
^ Git repo with tag (DEPRECATED. USE TAG OPTION)
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', ''
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
|
||||||
Plug 'junegunn/goyo.vim', '1.5.2'
|
Plug 'junegunn/goyo.vim', '1.5.2'
|
||||||
AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri
|
AssertEqual 'file:///tmp/vim-plug-test/junegunn/goyo.vim', g:plugs['goyo.vim'].uri
|
||||||
AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
|
AssertEqual join([g:temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
|
||||||
AssertEqual '1.5.2', g:plugs['goyo.vim'].tag
|
AssertEqual '1.5.2', g:plugs['goyo.vim'].tag
|
||||||
|
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {'tag': ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "tag" option of :Plug (expected: string)'
|
||||||
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
|
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
|
||||||
AssertEqual '1.5.3', g:plugs['goyo.vim'].tag
|
AssertEqual '1.5.3', g:plugs['goyo.vim'].tag
|
||||||
|
|
||||||
|
@ -77,6 +85,22 @@ Execute (Test Plug command):
|
||||||
|
|
||||||
Execute (Plug command with dictionary option):
|
Execute (Plug command with dictionary option):
|
||||||
Log string(g:plugs)
|
Log string(g:plugs)
|
||||||
|
for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as']
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {opt: ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string)'
|
||||||
|
endfor
|
||||||
|
for opt in ['on', 'for']
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {opt: ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "'.opt.'" option of :Plug (expected: string or list)'
|
||||||
|
endfor
|
||||||
|
redir => out
|
||||||
|
Plug 'foo/bar.vim', {'do': ''}
|
||||||
|
redir END
|
||||||
|
Assert out =~ 'Invalid argument for "do" option of :Plug (expected: string or funcref)'
|
||||||
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
|
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co', 'rtp': '././' }
|
||||||
AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
|
AssertEqual join([g:temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
|
||||||
AssertEqual '././', g:plugs['seoul256.vim'].rtp
|
AssertEqual '././', g:plugs['seoul256.vim'].rtp
|
||||||
|
@ -1037,9 +1061,10 @@ Execute (Post-update hook output; success and failure):
|
||||||
|
|
||||||
Execute (Post-update hook output; invalid type or funcref):
|
Execute (Post-update hook output; invalid type or funcref):
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
Plug 'junegunn/vim-easy-align', { 'do': 1 }
|
Plug 'junegunn/vim-easy-align', { 'do': ':echo 1' }
|
||||||
Plug 'junegunn/vim-pseudocl', { 'do': function('call') }
|
Plug 'junegunn/vim-pseudocl', { 'do': function('call') }
|
||||||
call plug#end()
|
call plug#end()
|
||||||
|
let g:plugs['vim-easy-align'].do = 1
|
||||||
|
|
||||||
silent PlugInstall! 1
|
silent PlugInstall! 1
|
||||||
AssertEqual 'x Post-update hook for vim-pseudocl ... Vim(call):E119: Not enough arguments for function: call', getline(5)
|
AssertEqual 'x Post-update hook for vim-pseudocl ... Vim(call):E119: Not enough arguments for function: call', getline(5)
|
||||||
|
|
Loading…
Reference in a new issue