Skip to content

Commit

Permalink
Datasource: Panic proof (#1723)
Browse files Browse the repository at this point in the history
Closes #1722
There shouldn't be any cases where it panics now
  • Loading branch information
julienduchesne authored Jul 26, 2024
1 parent e83dd62 commit edd6cc8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/resources/grafana/data_source_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ func datasourceDatasourceRead(ctx context.Context, d *schema.ResourceData, meta
resp, err = client.Datasources.GetDataSourceByName(name.(string))
} else if uid, ok := d.GetOk("uid"); ok {
resp, err = client.Datasources.GetDataSourceByUID(uid.(string))
} else {
return diag.Errorf("name or uid must be set")
}

if err != nil {
return diag.FromErr(err)
}

if resp == nil {
return diag.Errorf("unexpected state, API response is nil")
}

return datasourceToState(d, resp.GetPayload())
}

0 comments on commit edd6cc8

Please sign in to comment.