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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wrap provider to create new error structures #5278

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

dpopp07
Copy link
Contributor

@dpopp07 dpopp07 commented Apr 16, 2024

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 a diag.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 use flex.FmtErrorf instead of fmt.Errorf.

@hkantare

Community Note

  • Please vote on this pull request by adding a 馃憤 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

@hkantare
Copy link
Collaborator

Can you fix conflicts in go.mod and go.sum files

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.

Signed-off-by: Dustin Popp <dpopp07@gmail.com>
@hkantare hkantare merged commit 422d63d into IBM-Cloud:master Apr 29, 2024
1 check passed
@dpopp07 dpopp07 deleted the dp/wrapper-for-errors branch April 30, 2024 13:57
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.

None yet

2 participants