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

Store Address on V2 Target and pass it to Fields during validation #9300

Merged
merged 1 commit into from
Mar 14, 2020

Conversation

Eric-Arellano
Copy link
Contributor

@Eric-Arellano Eric-Arellano commented Mar 13, 2020

Problem

With the V2 Target API, by design, fields live independently of targets. This means that they cannot access any of the information from their parent target or be traced back to their original owner. For example, my_tgt.Get(Compatibility) will return Compatibility as a distinct type.

This is an issue during validation of fields. When validating a field, we need to refer to the original owning target to be able to generate a helpful error message that says which target the error comes from.

Beyond generating useful error messages, some AsyncFields need to use the Address to hydrate, such as Sources.

Solution

Change the constructor for Field to take Address.

However, we don't actually always store an Address field on every Field instance. PrimitiveFields have no use for the Address after they are validated in the constructor. It would be a non-trivial cost in space to store an Address on every single field ever encountered. So, PrimitiveFields use the Address during the constructor, and then throw away the value after.

In contrast to PrimitiveFields, AsyncFields are validated lazily, so they do need to preserve the Address as an attribute.

Result

Field validation can now have helpful error messages. We can also now use Address for AsyncFields, which allows us to implement Sources.

Remaining followup

In a followup, we will provide standard exception types to make it much easier for field/plugin authors to create high-quality error messages.

@Eric-Arellano Eric-Arellano merged commit d9c92e9 into pantsbuild:master Mar 14, 2020
@Eric-Arellano Eric-Arellano deleted the target-addresses branch March 14, 2020 01:03
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.

2 participants