-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Error Messaging Updates for Diagnostics #17314
Comments
Until this handling is decided, we could consider dropping any leading |
Excellent write up. I concur on sticking with one standard to facilitate future replacing of |
Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you! |
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. |
Community Note
Description
Given the age of the Terraform AWS Provider and some of its resources, there has been a long history of varied styles for returning resource error messages. Some places return no context (
return err
) while others return some additional context (return fmt.Errorf("...", err)
) with varied message styles.Through much of the history of these error messages (prior to Terraform CLI version 0.12), the user interface experience when showing these error messages was in a "
go-multierror
" style (destroy operation error shown below):Where Terraform CLI injected all this user interface output:
And the Terraform resource error was the remaining part (as sourced from
return ...
):When returning AWS Go SDK (e.g. API) error messages, the lack of returning error message context meant that practitioners could be faced with very confusing errors, such as this refresh operation example:
To rectify this, the maintainers moved towards requiring a consistent error messaging context including a noun and verb in addition to the actual error, so it was more clear about what was happening and where. e.g.
return fmt.Errorf("error creating/reading/updating/deleting Service Thing (%s): %w", d.Id(), err)
. This preferred style is documented in the Contributing Guide.Terraform CLI version 0.12 and later added support for resources to return both warning and error diagnostics in the user interface output. Diagnostics support both a summary and details fields. Given these changes, the output is now much more terse:
To compensate for existing resources that return a raw error type, the Terraform Plugin SDK converts these errors into an error diagnostic with the error message string in the summary field. Given the prior consistency standard for error messages, the error messaging now has an awkward output:
Rather than introduce yet more error message stylings with raw error types (since they should be updated anyways), it will likely be ideal to address this as or after resources are migrated to Terraform Plugin SDK version 2 and fully support diagnostics. This will allow resources to properly inject a summary and separate the details.
Some initial proposals include introducing helpers to wrap error messages before they are returned in resource logic. For example, having error diagnostic wrapper(s) such as:
Which the above could render as:
References
The text was updated successfully, but these errors were encountered: