Skip to content

Commit

Permalink
packer: check if errs is nil before getting length
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Apr 12, 2024
1 parent f8f8b2a commit d1a45ce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packer/plugin-getter/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,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)
}
Expand Down

0 comments on commit d1a45ce

Please sign in to comment.