-
Notifications
You must be signed in to change notification settings - Fork 15
Fix type assertion safety issues in DTO conversions and data transformations #846
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
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.
Pull Request Overview
This PR enhances type safety and error handling across DTO conversions to prevent panics and silent failures.
- Replace unchecked type assertions with safe checks and skips or error returns in tenant_settings and environment_group_rule_set.
- Handle and propagate errors from
ElementsAs
in DLP helper functions and update resource callers. - Add debug logging for cast failures in data_record converters and extend UUID type equality to support pointer types.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/services/tenant_settings/dto.go | Wrap unsafe assertions with ok checks and skip on failure |
internal/services/environment_group_rule_set/dto.go | Use safe assertions with error returns or skips for conversions |
internal/services/dlp_policy/helpers.go | Change convertToDlpEnvironment to return an error on failure |
internal/services/dlp_policy/resource_dlp_policy.go | Update callers to handle convertToDlpEnvironment errors |
internal/services/data_record/resource_data_record.go | Add debug logs for failed type casts in case* functions |
internal/customtypes/uuid_type.go | Extend Equal method to handle both value and pointer types |
Comments suppressed due to low confidence (4)
internal/services/tenant_settings/dto.go:222
- Add unit tests for the failure path when type assertions return
!ok
to ensure correct skip behavior is exercised.
objectValue, ok := teamIntegrationObject.(basetypes.ObjectValue)
internal/services/dlp_policy/resource_dlp_policy.go:335
- [nitpick] Enhance the diagnostic detail by including contextual information (e.g. which field or index failed) rather than only
err.Error()
.
if err != nil {
internal/customtypes/uuid_type.go:22
- [nitpick] Consider adding a doc comment for
Equal
to explain why pointer types are now supported and any implications for consumers.
func (t UUIDType) Equal(o attr.Type) bool {
internal/services/dlp_policy/helpers.go:221
- Update or add a function comment to reflect the new error return so callers understand that failures will now bubble up.
func convertToDlpEnvironment(ctx context.Context, environmentsInPolicy basetypes.SetValue) ([]dlpEnvironmentDto, error) {
…ings DTO conversions Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Co-authored-by: mattdot <266258+mattdot@users.noreply.github.com>
This PR fixes critical type safety issues in Data Transfer Object (DTO) conversions and data transformation operations that could cause runtime panics in the Terraform provider.
Issues Fixed
1. Unchecked Type Assertions in
tenant_settings/dto.go
Multiple conversion functions performed unsafe type assertions like
object.(basetypes.ObjectValue)
without checking for assertion failures:2. Unchecked Type Assertions in
environment_group_rule_set/dto.go
Similar unsafe patterns in AI generative settings, backup retention, and other conversion functions:
3. Ignored Error Returns in
dlp_policy/helpers.go
The
convertToDlpEnvironment
function ignored error returns fromElementsAs
:4. Silent Type Assertion Failures in
data_record/resource_data_record.go
Case functions silently ignored type assertion failures, leading to missing data:
5. Incomplete Type Support in
customtypes/uuid_type.go
The UUID type equality method only supported value types, not pointer types:
Impact
These fixes prevent:
Testing
Fixes #840.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.