SigNoz/signoz · error

params and builderQuery cannot be nil

Error message

params and builderQuery cannot be nil

What it means

prepareLogsQuery requires both the request params and the builder query to be non-nil; passing a nil v3.QueryRangeParamsV3 or a nil builderQuery inside the composite query returns this error before any SQL is built.

Source

Thrown at pkg/query-service/app/querier/v2/helper.go:31

	"github.com/SigNoz/signoz/pkg/query-service/common"
	"github.com/SigNoz/signoz/pkg/query-service/constants"
	v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
	"github.com/SigNoz/signoz/pkg/query-service/querycache"
	"github.com/SigNoz/signoz/pkg/valuer"
)

func prepareLogsQuery(
	_ context.Context,
	start,
	end int64,
	builderQuery *v3.BuilderQuery,
	params *v3.QueryRangeParamsV3,
) (string, error) {
	logsQueryBuilder := logsV4.PrepareLogsQuery
	query := ""

	if params == nil || builderQuery == nil {
		return query, fmt.Errorf("params and builderQuery cannot be nil")
	}

	// for ts query with limit replace it as it is already formed
	if params.CompositeQuery.PanelType == v3.PanelTypeGraph && builderQuery.Limit > 0 && len(builderQuery.GroupBy) > 0 {
		limitQuery, err := logsQueryBuilder(
			start,
			end,
			params.CompositeQuery.QueryType,
			params.CompositeQuery.PanelType,
			builderQuery,
			v3.QBOptions{GraphLimitQtype: constants.FirstQueryGraphLimit},
		)
		if err != nil {
			return query, err
		}
		placeholderQuery, err := logsQueryBuilder(
			start,
			end,

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Ensure every query in compositeQuery has a non-nil builder and the top-level params is initialized
  2. If building params from JSON, validate that builder is present for queryType QueryBuilder before calling QueryRange
  3. Add unit-test coverage constructing full params objects to catch nil fields early

Example fix

// before
params := &v3.QueryRangeParamsV3{CompositeQuery: &v3.CompositeQuery{Queries: []*v3.Query{{Name:"q", Builder: nil}}}}
// after
params := &v3.QueryRangeParamsV3{CompositeQuery: &v3.CompositeQuery{Queries: []*v3.Query{{Name:"q", Builder: &v3.BuilderQuery{...}}}}}
Defensive patterns

Strategy: type-guard

Validate before calling

if params == nil || params.CompositeQuery == nil { return errors.New("params required") }
for _, q := range params.CompositeQuery.Queries {
    if q.QueryType == v3.QueryTypeQueryBuilder && q.Builder == nil {
        return fmt.Errorf("query %s missing builder", q.Name)
    }
}

Type guard

func hasCompleteBuilderQueries(p *v3.QueryRangeParamsV3) bool {
    if p == nil || p.CompositeQuery == nil { return false }
    for _, q := range p.CompositeQuery.Queries {
        if q.QueryType == v3.QueryTypeQueryBuilder && q.Builder == nil { return false }
    }
    return true
}

Prevention

When it happens

Trigger: Programmatic (SDK/internal) calls to runBuilderQuery/prepareLogsQuery where params or the per-query BuilderQuery field is nil — e.g. constructing QueryRangeParamsV3 manually and leaving compositeQuery.queries[i].builder unset.

Common situations: Custom integrations building the params struct by hand, partial JSON deserialization leaving builder null, refactors that drop builderQuery population for logs queries.

Related errors


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