-
Notifications
You must be signed in to change notification settings - Fork 15
Fix missing return statements after error handling in datasources #827
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
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 ensures proper early returns after error handling in three datasource implementations to prevent panics and undefined behavior.
- Adds
return
statements after client error diagnostics in Connectors and Solutions datasources. - Introduces diagnostic error checking and early return for
resp.State.Get
in Tenant Application Packages datasource. - Updates changelog with the fix for issue [Copilot] Missing Return After Error Handling Issues #814.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/services/solution/datasource_solutions.go | Added return after DataverseExists error diagnostics |
internal/services/connectors/datasource_connectors.go | Added return after GetConnectors error diagnostics |
internal/services/application/datasource_tenant_application_packages.go | Appended diagnostics from resp.State.Get and early return on error |
.changes/unreleased/fixed-20250604-175056.yaml | Added changelog entry for this fix |
Comments suppressed due to low confidence (3)
internal/services/solution/datasource_solutions.go:137
- Add a unit test to simulate
DataverseExists
returning an error and verify thatresp.Diagnostics
contains the expected error and the method returns immediately without further processing.
return
internal/services/connectors/datasource_connectors.go:126
- Add a test case where
GetConnectors
returns an error to confirm that diagnostics are recorded and execution stops as intended.
return
internal/services/application/datasource_tenant_application_packages.go:174
- Introduce a test for a malformed state scenario where
resp.State.Get
returns diagnostics with errors, ensuring the new early return path is exercised.
diags := resp.State.Get(ctx, &state)
This PR fixes critical error handling issues in three datasource files where missing
return
statements after error diagnostics could lead to undefined behavior, panics, or data corruption.Issues Fixed
1. Connectors Datasource (
internal/services/connectors/datasource_connectors.go
)Problem: When
GetConnectors()
fails, an error is added to diagnostics but execution continues, potentially using invalidconnectors
data.2. Solutions Datasource (
internal/services/solution/datasource_solutions.go
)Problem: When
DataverseExists()
fails, an error is added to diagnostics but execution continues with undefineddvExits
value.3. Tenant Application Packages Datasource (
internal/services/application/datasource_tenant_application_packages.go
)Problem:
resp.State.Get()
doesn't check for errors in returned diagnostics, which could lead to panics with malformed state.Impact
These fixes prevent potential runtime panics, data corruption, and undefined behavior by ensuring proper error handling flow in critical datasource operations.
Testing
Fixes #814.
💡 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.