{"record":{"id":"ecacea8737abcb18","repo":"SigNoz/signoz","slug":"data-source-is-invalid-w","errorCode":null,"errorMessage":"data source is invalid: %w","messagePattern":"data source is invalid: %w","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/model/v3/v3.go","lineNumber":1032,"sourceCode":"\t\t}\n\t}\n\treturn false\n}\n\nfunc (b *BuilderQuery) Validate(panelType PanelType) error {\n\tif b == nil {\n\t\treturn nil\n\t}\n\n\tif b.QueryName == \"\" {\n\t\treturn fmt.Errorf(\"query name is required\")\n\t}\n\n\t// if expression is same as query name, it's a simple builder query and not a formula\n\t// formula involves more than one data source, aggregate operator, etc.\n\tif b.QueryName == b.Expression {\n\t\tif err := b.DataSource.Validate(); err != nil {\n\t\t\treturn fmt.Errorf(\"data source is invalid: %w\", err)\n\t\t}\n\t\tif b.DataSource == DataSourceMetrics {\n\t\t\t// if AggregateOperator is specified, then the request is using v3 payload\n\t\t\t// if b.AggregateOperator != \"\" && b.SpaceAggregation == SpaceAggregationUnspecified {\n\t\t\t// \tif err := b.AggregateOperator.Validate(); err != nil {\n\t\t\t// \t\treturn fmt.Errorf(\"aggregate operator is invalid: %w\", err)\n\t\t\t// \t}\n\t\t\t// } else {\n\t\t\t// \t// the time aggregation is not needed for percentile operators\n\t\t\t// \tif !IsPercentileOperator(b.SpaceAggregation) {\n\t\t\t// \t\tif err := b.TimeAggregation.Validate(); err != nil {\n\t\t\t// \t\t\treturn fmt.Errorf(\"time aggregation is invalid: %w\", err)\n\t\t\t// \t\t}\n\t\t\t// \t}\n\n\t\t\t// \tif err := b.SpaceAggregation.Validate(); err != nil {\n\t\t\t// \t\treturn fmt.Errorf(\"space aggregation is invalid: %w\", err)\n\t\t\t// \t}","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/model/v3/v3.go#L1014-L1050","documentation":"For a simple (non-formula) builder query (QueryName == Expression), the DataSource must be a valid value (metrics, logs, traces). %w wraps DataSource.Validate.","triggerScenarios":"Sending a builder query with dataSource \"\" or an unrecognized string like \"metric\".","commonSituations":"Omitting dataSource in hand-built payloads or using singular forms (\"metric\"/\"log\").","solutions":["Set dataSource to \"metrics\", \"logs\", or \"traces\" exactly","If the query is a pure formula, make sure expression differs from queryName so validation is skipped"],"exampleFix":"// before\n{\"dataSource\":\"metric\"}\n// after\n{\"dataSource\":\"metrics\"}","handlingStrategy":"type-guard","validationCode":"if q.QueryName == q.Expression { if err := q.DataSource.Validate(); err != nil { return err } }","typeGuard":"func isValidDataSource(d v3.DataSource) bool { return d.Validate() == nil }","tryCatchPattern":null,"preventionTips":["Use plural forms: metrics/logs/traces"],"tags":["go","enum-validation","data-source"],"backgroundTag":"invalid-enum-value","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}