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

tftypes: Consider Additional Errors for (Value).ApplyTerraform5AttributePathStep() #113

Open
bflad opened this issue Oct 4, 2021 · 1 comment
Labels
breaking-change This will impact or improve our compatibility posture enhancement New feature or request

Comments

@bflad
Copy link
Contributor

bflad commented Oct 4, 2021

terraform-plugin-go version

v0.4.0

Use cases

Downstream consumers using tftypes.WalkAttributePath() against a tftypes.Value tend to alway receive the same tftypes.ErrInvalidStep error, regardless of the cause, which may include:

  • Stepping into a null value
  • Stepping into an unknown value
  • Stepping into a type incorrectly (e.g. attempting WithAttributeName() on a List value)

The ability to distinguish between these situations means that these consumers can further tailor their intended behaviors, without the need to then determine the underlying cause.

Attempted solutions

After receiving ErrInvalidStep, walk backwards in the path (via recursive (AttributePath).WithoutLastStep() until no ErrInvalidStep is received) to detect a parent value with IsUnknown().

Proposal

Create two new error values (one for stepping into a null value, one for stepping into an unknown value) and convert this logic to use them:

	if !val.IsKnown() || val.IsNull() {
		return nil, ErrInvalidStep
	}

e.g.

	if val.IsNull() {
		return nil, ErrInvalidStepNullValue
	}

	if !val.IsKnown() {
		return nil, ErrInvalidStepUnknownValue
	}

In the error implementation, they should still be appropriately detectable via errors.Is(tftypes.ErrInvalidStep) or this enhancement becomes a breaking change.

References

@bflad
Copy link
Contributor Author

bflad commented Dec 6, 2021

Breaking change 👍 ErrInvalidStep should be migrated to a new name so it is very clear that usage should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will impact or improve our compatibility posture enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant