Skip to content

Commit edd6cc8

Browse files
Datasource: Panic proof (#1723)
Closes #1722 There shouldn't be any cases where it panics now
1 parent e83dd62 commit edd6cc8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/resources/grafana/data_source_data_source.go

+6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ func datasourceDatasourceRead(ctx context.Context, d *schema.ResourceData, meta
4444
resp, err = client.Datasources.GetDataSourceByName(name.(string))
4545
} else if uid, ok := d.GetOk("uid"); ok {
4646
resp, err = client.Datasources.GetDataSourceByUID(uid.(string))
47+
} else {
48+
return diag.Errorf("name or uid must be set")
4749
}
4850

4951
if err != nil {
5052
return diag.FromErr(err)
5153
}
5254

55+
if resp == nil {
56+
return diag.Errorf("unexpected state, API response is nil")
57+
}
58+
5359
return datasourceToState(d, resp.GetPayload())
5460
}

0 commit comments

Comments
 (0)