feat: wrap provider to create new error structures #5278
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds code that wraps the provider in order to catch errors and re-format them with the new system, to minimize the surface area of the changes required for non-generated resource/data source code.
The primary change to resource code comes in the from of updating calls to
fmt.Errorf
to be calls to a new wrapper function,flex.FmtErrorf
. It accepts the same arguments but instead of wrapping errors coming from the underlying Go SDK so that we retain only the message, it creates instances of the new TerraformProblem type to be propagated to the wrapped provider code. This way, we preserve all of the information needed for the new error formats, including the information from previous errors.Note: This PR just creates the baseline support. Resource code that returns an
error
(rather than adiag.Diagnostics
will start to get support for new errors right away, but they will not have all information needed from previous errors in the SDK. For that, individual service teams will need to update their code to useflex.FmtErrorf
instead offmt.Errorf
.@hkantare
Community Note