From 27a77de012cf5c0f4e5694ba6b5b906078cf7a0f Mon Sep 17 00:00:00 2001 From: Liam Cervante Date: Fri, 8 Jul 2022 16:51:36 +0100 Subject: [PATCH] improve error message --- internal/command/init.go | 6 +++--- internal/getproviders/errors.go | 2 +- internal/providercache/errors.go | 6 ++++-- internal/providercache/package_install.go | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/command/init.go b/internal/command/init.go index 41ec3e501fae..13c31d9adca0 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -761,7 +761,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 @@ -770,8 +770,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(), ), )) diff --git a/internal/getproviders/errors.go b/internal/getproviders/errors.go index c612dedf2c49..cd110a2b1f33 100644 --- a/internal/getproviders/errors.go +++ b/internal/getproviders/errors.go @@ -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, diff --git a/internal/providercache/errors.go b/internal/providercache/errors.go index ac81e880a0a1..75550d008921 100644 --- a/internal/providercache/errors.go +++ b/internal/providercache/errors.go @@ -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 } diff --git a/internal/providercache/package_install.go b/internal/providercache/package_install.go index 4566a4a608f6..e07564b61bd6 100644 --- a/internal/providercache/package_install.go +++ b/internal/providercache/package_install.go @@ -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", @@ -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)",