Skip to content

Commit

Permalink
backport of commit 27a77de
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcervante committed Jul 8, 2022
1 parent c9bb3f7 commit 99665e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/command/init.go
Expand Up @@ -756,7 +756,7 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
// but rather just emit a single general message about it at
// the end, by checking ctx.Err().

case providercache.ErrChecksumMiss:
case providercache.ErrProviderChecksumMiss:
// This is a special kind of error that can often be fixed using
// the `terraform providers lock` command. We're just going to
// amend the actual error message with some extra information
Expand All @@ -765,8 +765,8 @@ func (c *InitCommand) getProviders(config *configs.Config, state *states.State,
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to install provider",
fmt.Sprintf("Error while installing %s v%s: %s\n\nUse the `terraform providers lock` command to include all necessary platforms in the dependency lock file. Ensure the current platform, %s, is included.",
provider.ForDisplay(), version, err.Msg, err.Meta.TargetPlatform.String(),
fmt.Sprintf("Error while installing %s v%s: %s\n\nYou can ensure the current platform, %s, is included in the dependency lock file by running: `terraform providers lock -provider=%s`.\n\nIf this does not fix the problem you may need to reset any provider caching present in your setup or make sure you are connecting to valid provider distributions.",
provider.ForDisplay(), version, err.Msg, err.Meta.TargetPlatform.String(), err.Meta.TargetPlatform.String(),
),
))

Expand Down
2 changes: 1 addition & 1 deletion internal/getproviders/errors.go
Expand Up @@ -210,7 +210,7 @@ func (err ErrQueryFailed) Unwrap() error {
return err.Wrapped
}

// ErrRequestCancelled is an error type used to indicate that an operation
// ErrRequestCanceled is an error type used to indicate that an operation
// failed due to being cancelled via the given context.Context object.
//
// This error type doesn't include information about what was cancelled,
Expand Down
6 changes: 4 additions & 2 deletions internal/providercache/errors.go
Expand Up @@ -2,11 +2,13 @@ package providercache

import "github.com/hashicorp/terraform/internal/getproviders"

type ErrChecksumMiss struct {
// ErrProviderChecksumMiss is an error type used to indicate a provider
// installation failed due to a mismatch in the terraform provider lock file.
type ErrProviderChecksumMiss struct {
Meta getproviders.PackageMeta
Msg string
}

func (err ErrChecksumMiss) Error() string {
func (err ErrProviderChecksumMiss) Error() string {
return err.Msg
}
4 changes: 2 additions & 2 deletions internal/providercache/package_install.go
Expand Up @@ -116,7 +116,7 @@ func installFromLocalArchive(ctx context.Context, meta getproviders.PackageMeta,
meta.Provider, meta.Version, meta.Location, err,
)
} else if !matches {
return authResult, ErrChecksumMiss{
return authResult, ErrProviderChecksumMiss{
Meta: meta,
Msg: fmt.Sprintf(
"the current package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file",
Expand Down Expand Up @@ -201,7 +201,7 @@ func installFromLocalDir(ctx context.Context, meta getproviders.PackageMeta, tar
meta.Provider, meta.Version, meta.Location, err,
)
} else if !matches {
return authResult, ErrChecksumMiss{
return authResult, ErrProviderChecksumMiss{
Meta: meta,
Msg: fmt.Sprintf(
"the local package for %s %s doesn't match any of the checksums previously recorded in the dependency lock file (this might be because the available checksums are for packages targeting different platforms)",
Expand Down

0 comments on commit 99665e3

Please sign in to comment.