packer: check if errs is nil before getting length

When installing a remote plugin, and after we've either successfully
installed a binary, or exhausted all the possible sources, we print a
final error message if nothing was reported.

However, given that errs is a pointer to a structure, and if no errors
were produced, the the error list could be nil, leading to the call to
`Len()' to crash Packer.

This is exceedingly rare as in general the code attempts to read
multiple sources from Github, and therefore we almost always get some
error reported, but while changing the function's code, I managed to
make it crash while removing/changing some error statements.

Therefore to avoid future surprises, we first check that `errs' is not
nil before invoking `Len()' on it, as no errors and no plugins installed
mean that something went wrong all the same.
pull/12964/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 56fab30fa1
commit d40df8e899

@ -917,7 +917,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
}
}
if errs.Len() == 0 {
if errs == nil || errs.Len() == 0 {
err := fmt.Errorf("could not find a local nor a remote checksum for plugin %q %q", pr.Identifier, pr.VersionConstraints)
errs = multierror.Append(errs, err)
}

Loading…
Cancel
Save