Skip to content

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

Merged
merged 5 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/unreleased/fixed-20250604-175056.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: fixed
body: Fixed missing return statements after error handling in three datasources to prevent potential panics and undefined behavior
time: 2025-06-04T17:50:56.587490569Z
custom:
Issue: "814"
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ func (d *TenantApplicationPackagesDataSource) Read(ctx context.Context, req data
defer exitContext()

var state TenantApplicationPackagesListDataSourceModel
resp.State.Get(ctx, &state)
diags := resp.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

state.Name = types.StringValue(state.Name.ValueString())
state.PublisherName = types.StringValue(state.PublisherName.ValueString())
Expand Down Expand Up @@ -213,7 +217,7 @@ func (d *TenantApplicationPackagesDataSource) Read(ctx context.Context, req data
state.Applications = append(state.Applications, app)
}

diags := resp.State.Set(ctx, &state)
diags = resp.State.Set(ctx, &state)

resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand Down
1 change: 1 addition & 0 deletions internal/services/connectors/datasource_connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
connectors, err := d.ConnectorsClient.GetConnectors(ctx)
if err != nil {
resp.Diagnostics.AddError(fmt.Sprintf("Client error when reading %s", d.FullTypeName()), fmt.Errorf("error occurred: %w", err).Error())
return
}

for _, connector := range connectors {
Expand Down
1 change: 1 addition & 0 deletions internal/services/solution/datasource_solutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (d *DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp
dvExits, err := d.SolutionClient.DataverseExists(ctx, state.EnvironmentId.ValueString())
if err != nil {
resp.Diagnostics.AddError(fmt.Sprintf("Client error when checking if Dataverse exists in environment '%s'", state.EnvironmentId.ValueString()), err.Error())
return
}

if !dvExits {
Expand Down