Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exit error types #352

Merged
merged 2 commits into from
Feb 20, 2023
Merged

Remove exit error types #352

merged 2 commits into from
Feb 20, 2023

Conversation

kmoe
Copy link
Member

@kmoe kmoe commented Jan 10, 2023

Closes #296.

This PR proposes a breaking change to the terraform-exec API removing the following error types:
ErrConfigInvalid
ErrLockIdInvalid
ErrMissingVar
ErrNoConfig
ErrNoInit
ErrNoWorkspace
ErrStateLocked
ErrStatePlanRead
ErrTFVersionMismatch
ErrWorkspaceExists

The above error types are returned based on parsing the human-readable output of Terraform CLI via regex. The human-readable output of Terraform CLI is not designed for machine parsing, and can change at any time, as it is not covered by the Terraform v1.x Compatibility Promises. These changes, along with trivial text formatting issues, are a common cause of test failures in terraform-exec.

I don't think maintaining these is worth the work, in the absence of a clear use case for these errors. If you have one, please comment here or on the linked issue.

Note that the following errors are not removed:
ErrVersionMismatch
ErrNoSuitableBinary
ErrManualEnvVar

In particular, the compatibility error ErrVersionMismatch, which is based on terraform-exec's knowledge of which flags and commands can be used with which version of Terraform, is not removed.


As Terraform's machine-readable UI (-json streaming format) matures, I expect Terraform itself is the best place to build more structure into errors and diagnostics if necessary. For example, diagnostics could contain an error symbol in addition to their human-readable summary and description.

@kmoe kmoe requested review from bflad and radeksimko January 10, 2023 12:12
@kmoe kmoe marked this pull request as ready for review January 10, 2023 12:12
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 🚀

_, err := tf.Show(context.Background())
if !errors.As(err, &noInit) {
t.Fatalf("expected error ErrNoInit, got %T: %s", err, err)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not sure if its worth checking for the (new) expected error in these cases or not.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change in principle LGTM, but there's now a number of tests which are failing, so I think we either need to reconsider the scope, or change the tests.

@kmoe
Copy link
Member Author

kmoe commented Feb 10, 2023

Rebased, but this change unintentionally broke the context.DeadlineExceeded wrapping introduced in 592bcd1 (see golang/go#21880). Fixing.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do any "deeper" checks in terms of reading through the relevant LS code, but I can confirm that all LS tests are still passing with these changes, i.e. we aren't relying on any of the error types being removed in LS.

Let's ship it!

Time will tell how much we're affected by Hyrum's Law 😁

@kmoe kmoe merged commit a7e018d into main Feb 20, 2023
@kmoe kmoe deleted the kmoe/remove-custom-errors branch February 20, 2023 09:29
@sergiught
Copy link

This change unfortunately makes all our test cases that expect an error fail within https://github.com/auth0/terraform-provider-auth0 e.g.

func TestAccBranding_WithNoCustomDomainsSet(t *testing.T) {
	acctest.Test(t, resource.TestCase{
		Steps: []resource.TestStep{
			{
				Config: testAccTenantDisallowsUniversalLoginCustomization,
				ExpectError: regexp.MustCompile(
					"managing the universal login body through the 'auth0_branding' resource " +
						"requires at least one custom domain to be configured for the tenant",
				),
			},
		},
	})
}

To reproduce:

git clone git@github.com:auth0/terraform-provider-auth0.git
cd terraform-provider-auth0
go mod vendor
make test-acc FILTER="TestAccBranding_WithNoCustomDomainsSet" // test passing
go get github.com/hashicorp/terraform-exec@v0.18.0
go mod vendor
make test-acc FILTER="TestAccBranding_WithNoCustomDomainsSet" // test failing

@kmoe
Copy link
Member Author

kmoe commented Mar 1, 2023

Thanks @sergiught, we're looking into this now. Stderr did not make it into the error wrapping, it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider removing exported error types
4 participants