-
Notifications
You must be signed in to change notification settings - Fork 233
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
Diagnostics Proposal #368
Diagnostics Proposal #368
Conversation
var ds []*proto.Diagnostic | ||
for _, d := range diags { | ||
if err := d.Validate(); err != nil { | ||
panic(fmt.Errorf("Invalid diagnostic: %s. This is always a bug in the provider implementation", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this is an Errorf
inside the panic? Should this func just return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to add the line that this should be considered a bug in the provider implementation, hence the interpolation/fmt. Wanted the errors coming from the diagnostic validation to be terse
Temporarily converted to draft while we work out the |
build cty.Path as we dive through validation stack
make Error string of Diagnostic include detail introduce MapKey to associate diag to proper attribute for maps during validation
Worth noting expecting strings for expected errors is brittle should at least search for regex or substrings update all internal use to diags.Append
Ensure both ValidateFunc and ValidateDiagFunc can't be set truncate TypeSet attribute path and explain why
remove JoinPath helper
change RequiredWith to use diagnostics
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This PR implements diagnostics for validation, CRUD, and ConfigureContextFunc. There are breaking changes to some functions along the callstack but they are functions mostly considered "internal" despite being publicly exported.
Usage
For diagnostics support in the other areas of the SDK (such as the context aware CRUD) the usage is similar except the developer is responsible for constructing and setting the path entirely (validation is unique in that the SDK drills down the schema)
TypeSet
Unfortunately
schema.TypeSet
cannot be represented as an attribute path with the current protocol. In the case of validation the path is truncated at that attribute, which will provide some context to the user but it is not perfect, err on the side of verbose wording for diagnostics that are a child ofTypeSet
.We are still investigating having guardrails around this in the CRUD API so developers don't create invalid paths in general (relative to their schema definition). The situation isn't so bad though as Terraform will just render blank where the line and file info would have been (not great but also nonfatal)