Skip to content
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

Fix potential panic on dashboards #931

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion internal/resources/grafana/resource_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func NormalizeDashboardConfigJSON(config interface{}) string {
// from the dashboard JSON other than "name" or "uid".
// Grafana will populate all other libraryPanel attributes, so delete them to avoid diff.
panels, hasPanels := dashboardJSON["panels"]
if hasPanels {
if hasPanels && panels != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is:

panic: interface conversion: interface {} is nil, not []interface {}

Wouldn't perhaps the right check be?

Suggested change
if hasPanels && panels != nil {
if _, ok := pabels.([]interface{}); ok && hasPanels {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasPanels is useless in that case. I think we only need the cast in fact: https://go.dev/play/p/qCqc3sQfkNk

for _, panel := range panels.([]interface{}) {
panelMap := panel.(map[string]interface{})
delete(panelMap, "id")
Expand Down