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

provider functions can only return an error #34603

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Jan 31, 2024

The call site for language functions doesn't currently have a way to handle complex diagnostics, so rather than appear to support them in the protocol we remove the concept of diagnostics for now. We do however retain the argument index field, which we can wrap in a function.ArgError to get a little more precise hcl diagnostic from the expression.

@jbardin jbardin requested a review from bflad January 31, 2024 20:31
@jbardin jbardin force-pushed the jbardin/remove-provider-funtion-warnings branch from 44f5958 to 6817e76 Compare January 31, 2024 20:35
@jbardin jbardin force-pushed the jbardin/remove-provider-funtion-warnings branch from 6817e76 to c34c53e Compare January 31, 2024 20:54
@jbardin jbardin changed the title provider functions return an error provider functions can only return an error Jan 31, 2024
Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

It seems to me that this is essentially a one-way door because if we did want to add back support for arbitrary diagnostics later then we'd need to find some way to stuff at least the error ones into this error field for backward-compatibility with older Terraform Core versions that wouldn't know to look for the diagnostics. We'd also not be able to rely on everyone seeing any warnings that a function returns, which would limit the situations where it would be useful to return them.

Given that, I think we should just go all-in on this thing being shaped like a decision between plain error and cty/function.ArgError, and thus reduce this to just a single message and optional function_argument, rather than having it be sorta-kinda-diagnostic-shaped. 🤔

I would then expect the plugin framework to represent functions in a similar way to how cty/function does, where they return error and then it type-asserts for a specific error type to decide whether to populate that function_argument field.

@jbardin
Copy link
Member Author

jbardin commented Feb 1, 2024

I don't think this is a one-way door per say, but I do think changing the function call site for all existing functions to handle diagnostics is much harder than re-extending this particular function implementation on its own. I agree that having this be a half-diagnostic doesn't really benefit us, so we might as well make it a simple error with optional function_argument.

The call site for language functions doesn't currently have a way to
handle complex diagnostics, so rather than appear to support them in the
protocol we remove the concepts of diagnostics for now. We do however
retain the argument index fields, which we can wrap in a
function.ArgError and get a little more precise hcl diagnostic from
expression.
@jbardin jbardin force-pushed the jbardin/remove-provider-funtion-warnings branch from c34c53e to a8701f6 Compare February 1, 2024 14:27
@jbardin jbardin marked this pull request as ready for review February 9, 2024 14:22
bendbennett added a commit to hashicorp/terraform-plugin-go that referenced this pull request Feb 21, 2024
… with function error

Reference: hashicorp/terraform#34603

The next version of the plugin protocol (5.5/6.5) includes support for provider defined functions. This change modifies the response returned from the CallFunction RPC, replacing diagnostics with function error.
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.

We'll be pushing out the provider side changes to match this 👍

bendbennett added a commit to hashicorp/terraform-plugin-go that referenced this pull request Feb 22, 2024
… with function error (#380)

* tfprotov5+tfprotov6: Replace usage of diagnostics in CallFunction RPC with function error
Reference: hashicorp/terraform#34603

The next version of the plugin protocol (5.5/6.5) includes support for provider defined functions. This change modifies the response returned from the CallFunction RPC, replacing diagnostics with function error.

* Fix protoc version

* Add changelog

* Removing function argument from diagnostics

* Renaming param from msg to text for function errorr

* Adding change log
@jbardin jbardin merged commit 300f66b into main Feb 27, 2024
6 checks passed
@jbardin jbardin deleted the jbardin/remove-provider-funtion-warnings branch February 27, 2024 14:53
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants