-
Notifications
You must be signed in to change notification settings - Fork 15
Fix unsafe type assertions in provider data handling #847
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Copilot finished work on behalf of
mawasile
June 5, 2025 15:15
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 improves provider reliability by replacing unsafe direct type assertions with safe, conditional checks that prevent runtime panics and clarify error messages. Key changes include:
- Replacing unsafe type assertions with safe checks for provider data in resource configuration.
- Updating error messages to correctly indicate the expected type (*api.ProviderClient) instead of *http.Client.
- Applying these changes across multiple resource and datasource files.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
internal/services/tenant_settings/resource_tenant_settings.go | Updated safe type assertion for tenant settings with revised error messaging. |
internal/services/managed_environment/resource_managed_environment.go | Introduced a nil check for the Api field before client initialization. |
internal/services/languages/datasource_languages.go | Applied safe type assertion and updated error messaging in the Languages datasource. |
internal/services/environment_settings/resources_environment_settings.go | Modified safe type assertion for environment settings resources. |
internal/services/environment_group_rule_set/resource_environment_group_rule_set.go | Revised safe type assertion and error messaging for environment group rule sets. |
internal/services/data_record/resource_data_record.go | Implemented safe type assertion in the Data Record resource configuration. |
internal/services/data_record/datasource_data_record.go | Updated safe type assertion for the Data Record datasource. |
.changes/unreleased/fixed-20250605-151206.yaml | Documented the fix in the unreleased changes log. |
mawasile
approved these changes
Jun 9, 2025
mattdot
approved these changes
Jun 12, 2025
eduardodfmex
approved these changes
Jun 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ai assisted
Pull requests that have be fully or partially implemented using Copilot or AI
ai found
Issues and Bugs that were found using AI
copilot
fixed using GitHub copilot autonomous agent
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 PR addresses critical type assertion safety issues in the Terraform provider that could cause runtime panics and misleading error messages.
Issues Fixed
Issue 1: Unsafe Direct Type Assertion
Several Configure functions were performing direct type assertions without safety checks:
Issue 2: Misleading Error Messages
When type assertions failed or Api was nil, error messages incorrectly referenced
*http.Client
instead of the actual expected type:Solution
Replaced all unsafe type assertions with the safe pattern used elsewhere in the codebase:
For cases where additional nil checks were needed, provided clear error messages:
Files Changed
internal/services/environment_group_rule_set/resource_environment_group_rule_set.go
internal/services/managed_environment/resource_managed_environment.go
internal/services/environment_settings/resources_environment_settings.go
internal/services/languages/datasource_languages.go
internal/services/data_record/datasource_data_record.go
internal/services/data_record/resource_data_record.go
internal/services/tenant_settings/resource_tenant_settings.go
Testing
These changes improve provider reliability by preventing potential runtime panics and providing clearer error messages for debugging configuration issues.
Fixes #841.
💡 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.