backend/remote: remove milseading contents from error message (#22148)

Previously, terraform was returning a potentially-misleading error
message in response to anything other than a 404 from the
b.client.Workspaces.Read operation. This PR simplifies Terraform's error
message with the intent of encouraging those who encounter it to focus
on the error message returned from the tfe client.

The added test is odd, and a bit hacky, and possibly overkill.
This commit is contained in:
Kristin Laemmert 2019-07-22 09:06:39 -04:00 committed by GitHub
parent 4c337cc51d
commit 412d459292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 5 deletions

View File

@ -657,11 +657,7 @@ func (b *Remote) Operation(ctx context.Context, op *backend.Operation) (*backend
)
default:
return nil, fmt.Errorf(
"%s\n\n"+
"The configured \"remote\" backend encountered an unexpected error. Sometimes\n"+
"this is caused by network connection problems, in which case you could retr\n"+
"the command. If the issue persists please open a support ticket to get help\n"+
"resolving the problem.",
"The configured \"remote\" backend encountered an unexpected error:\n\n%s",
err,
)
}

View File

@ -948,6 +948,11 @@ func (m *mockWorkspaces) Create(ctx context.Context, organization string, option
}
func (m *mockWorkspaces) Read(ctx context.Context, organization, workspace string) (*tfe.Workspace, error) {
// custom error for TestRemote_plan500 in backend_plan_test.go
if workspace == "network-error" {
return nil, errors.New("I'm a little teacup")
}
w, ok := m.workspaceNames[workspace]
if !ok {
return nil, tfe.ErrResourceNotFound

View File

@ -855,3 +855,23 @@ func TestRemote_planWithRemoteError(t *testing.T) {
t.Fatalf("expected plan error in output: %s", output)
}
}
func TestRemote_planOtherError(t *testing.T) {
b, bCleanup := testBackendDefault(t)
defer bCleanup()
op, configCleanup := testOperationPlan(t, "./testdata/plan")
defer configCleanup()
op.Workspace = "network-error" // custom error response in backend_mock.go
_, err := b.Operation(context.Background(), op)
if err == nil {
t.Errorf("expected error, got success")
}
if !strings.Contains(err.Error(),
"The configured \"remote\" backend encountered an unexpected error:\n\nI'm a little teacup") {
t.Fatalf("expected error message, got: %s", err.Error())
}
}