: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:
Jan Edmund Lazo
2020-06-03 07:34:44 -04:00
committed by GitHub
parent 71c41fccf5
commit 6583b99032
2 changed files with 49 additions and 2 deletions

View File

@@ -632,17 +632,39 @@ function! plug#(repo, ...)
let g:plugs[name] = spec
let s:loaded[name] = get(s:loaded, name, 0)
catch
return s:err(v:exception)
return s:err(repo . ' ' . v:exception)
endtry
endfunction
function! s:parse_options(arg)
let opts = copy(s:base_spec)
let type = type(a:arg)
let opt_errfmt = 'Invalid argument for "%s" option of :Plug (expected: %s)'
if type == s:TYPE.string
if empty(a:arg)
throw printf(opt_errfmt, 'tag', 'string')
endif
let opts.tag = a:arg
elseif type == s:TYPE.dict
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')
let opts.dir = s:dirpath(s:plug_expand(opts.dir))
endif