Skip to content

Commit

Permalink
Fix the NPE issue in provisioner resource/datasource
Browse files Browse the repository at this point in the history
Added the fix to return without trying to parse the nil response in case of any error.

Signed-off-by: Ramya Bangera <bangerar@vmware.com>
  • Loading branch information
ramya-bangera committed Jan 19, 2024
1 parent e782184 commit 99582ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/resources/provisioner/data_source_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ func dataSourceProvisionerRead(ctx context.Context, d *schema.ResourceData, m in

if model.FullName.Name == "" {
resp, err := config.TMCConnection.ProvisionerResourceService.ProvisionerResourceServiceList(model.FullName)

Check failure on line 60 in internal/resources/provisioner/data_source_provisioner.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
}
return

Check failure on line 66 in internal/resources/provisioner/data_source_provisioner.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

for i := range resp.Provisioners {
Expand All @@ -78,6 +80,7 @@ func dataSourceProvisionerRead(ctx context.Context, d *schema.ResourceData, m in
_ = schema.RemoveFromState(d, m)
return
}
return
}

d.SetId(resp.Provisioner.Meta.UID)
Expand Down
2 changes: 2 additions & 0 deletions internal/resources/provisioner/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ func resourceProvisionerRead(ctx context.Context, d *schema.ResourceData, m inte
}

resp, err := config.TMCConnection.ProvisionerResourceService.ProvisionerResourceServiceGet(model.FullName)

Check failure on line 145 in internal/resources/provisioner/resource_provisioner.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
}
return

Check failure on line 151 in internal/resources/provisioner/resource_provisioner.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

d.SetId(resp.Provisioner.Meta.UID)
Expand Down

0 comments on commit 99582ee

Please sign in to comment.