SigNoz/signoz · error

dashboard_invalid_widget_query

dashboard_invalid_widget_query

Error message

cannot type cast query name as string

What it means

GetWidgetQuery iterates builder query data maps and requires each entry's queryName key to be a JSON string. When queryName is absent, a number, or another type, the type assertion query["queryName"].(string) fails with this error.

Source

Thrown at pkg/types/dashboardtypes/dashboard.go:369

	var data dashboardData
	err = json.Unmarshal(dataJSON, &data)
	if err != nil {
		return nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeDashboardInvalidData, "invalid dashboard data")
	}

	if int(widgetIndex) >= len(data.Widgets) {
		return nil, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidInput, "widget with index %v doesn't exist", widgetIndex)
	}

	compositeQueries := []any{}
	widgetData := data.Widgets[widgetIndex]
	switch widgetData.Query.QueryType {
	case "builder":
		for _, query := range widgetData.Query.Builder.QueryData {
			queryName, ok := query["queryName"].(string)
			if !ok {
				return nil, errors.New(errors.TypeInvalidInput, ErrCodeDashboardInvalidWidgetQuery, "cannot type cast query name as string")
			}
			compositeQueries = append(compositeQueries, querybuildertypesv5.WrapInV5Envelope(queryName, query, "builder_query"))
		}
		for _, query := range widgetData.Query.Builder.QueryFormulas {
			queryName, ok := query["queryName"].(string)
			if !ok {
				return nil, errors.New(errors.TypeInvalidInput, ErrCodeDashboardInvalidWidgetQuery, "cannot type cast query name as string")
			}
			compositeQueries = append(compositeQueries, querybuildertypesv5.WrapInV5Envelope(queryName, query, "builder_formula"))
		}
		for _, query := range widgetData.Query.Builder.QueryTraceOperator {
			queryName, ok := query["queryName"].(string)
			if !ok {
				return nil, errors.New(errors.TypeInvalidInput, ErrCodeDashboardInvalidWidgetQuery, "cannot type cast query name as string")
			}
			compositeQueries = append(compositeQueries, querybuildertypesv5.WrapInV5Envelope(queryName, query, "builder_trace_operator"))
		}
	case "clickhouse_sql":

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Ensure every queryData entry has "queryName":"A" style string
  2. Fix the import/conversion script to stringify query names
  3. Validate dashboard JSON against the builder schema before save
  4. Re-save the widget from the UI editor which enforces string names

Example fix

// before
{"queryName":1,"expression":"..."}
// after
{"queryName":"1","expression":"..."}
Defensive patterns

Strategy: type-guard

Validate before calling

widget.query?.builder?.queryData?.every(q => typeof q.queryName === 'string') ?? true

Type guard

function validQueryData(qs: Array<Record<string, unknown>>): boolean { return qs.every(q => typeof q.queryName === 'string'); }

Prevention

When it happens

Trigger: Dashboard widget with query.builder.queryData entries where queryName is missing or non-string (e.g. numeric 1); dashboards imported/converted from other formats that normalize names to numbers.

Common situations: Hand-edited dashboard JSON; conversion tools from Grafana/Perses that emit integer query names; frontend regressions writing queryName as a number.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/939c6df5ca59e311. Report an issue: GitHub.