{"record":{"id":"c6697924d4af1ff1","repo":"jaegertracing/jaeger","slug":"cannot-encode-the-query-filter-w","errorCode":null,"errorMessage":"cannot encode the query filter: %w","messagePattern":"cannot encode the query filter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/jaeger/internal/integration/trace_reader.go","lineNumber":145,"sourceCode":"// Reader, so a predicate this function drops is one no e2e test can exercise.\nfunc toProtoQuery(query tracestore.TraceQueryParams) (*api_v3.TraceQueryParameters, error) {\n\tif query.SearchDepth > math.MaxInt32 {\n\t\treturn nil, fmt.Errorf(\"SearchDepth must not be greater than %d\", math.MaxInt32)\n\t}\n\tprotoQuery := &api_v3.TraceQueryParameters{\n\t\tServiceName:   query.ServiceName,\n\t\tOperationName: query.OperationName,\n\t\tAttributes:    jptrace.PcommonMapToPlainMap(query.Attributes),\n\t\tStartTimeMin:  query.StartTimeMin,\n\t\tStartTimeMax:  query.StartTimeMax,\n\t\tDurationMin:   query.DurationMin,\n\t\tDurationMax:   query.DurationMax,\n\t\tSearchDepth:   int32(query.SearchDepth), //nolint:gosec // G115 - bounds checked above\n\t}\n\tif query.Filter != nil {\n\t\tfilter, err := expressionproto.ToProto(query.Filter)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot encode the query filter: %w\", err)\n\t\t}\n\t\tprotoQuery.Filter = filter\n\t}\n\treturn protoQuery, nil\n}\n\nfunc (r *traceReader) FindTraces(\n\tctx context.Context,\n\tquery tracestore.TraceQueryParams,\n) iter.Seq2[[]ptrace.Traces, error] {\n\treturn func(yield func([]ptrace.Traces, error) bool) {\n\t\tprotoQuery, err := toProtoQuery(query)\n\t\tif err != nil {\n\t\t\tyield(nil, err)\n\t\t\treturn\n\t\t}\n\t\tprotoQuery.RawTraces = true\n\t\tstream, err := r.client.FindTraces(ctx, &api_v3.FindTracesRequest{Query: protoQuery})","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/cmd/jaeger/internal/integration/trace_reader.go#L127-L163","documentation":"When the query carries a filter expression, toProtoQuery encodes it to protobuf via expressionproto.ToProto. If the expression cannot be represented as a proto filter (unsupported operator, malformed value type), the error is wrapped as 'cannot encode the query filter' and the search fails.","triggerScenarios":"A tracestore search is issued with query.Filter set to an expression that expressionproto.ToProto cannot serialize — e.g. an operator or value type with no proto representation.","commonSituations":"Tests or callers constructing filter expressions programmatically with operators unsupported by the api_v3 filter proto; mixing value types the proto schema does not accept; version skew between the expression library and the proto definition.","solutions":["Inspect the wrapped error to identify which part of the expression failed to encode","Simplify or rewrite the filter using operators/value types supported by the api_v3 filter proto","If the filter came from user input, validate it against the supported expression grammar before issuing the query"],"exampleFix":"// before\nfilter, _ := expr.NewComparison(\"tags.x\", expr.Equals, someCustomType{})\n// after\nfilter, _ := expr.NewComparison(\"tags.x\", expr.Equals, \"string-value\")","handlingStrategy":"validation","validationCode":"// validate filter before querying\nast, err := expr.Parse(filterStr)\nif err != nil { return err }\nif err := expr.ValidateSupported(ast, expressionproto.SupportedOperators()); err != nil {\n    return fmt.Errorf(\"filter uses unsupported constructs: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"q, err := toProtoQuery(params)\nif err != nil && strings.Contains(err.Error(), \"cannot encode the query filter\") {\n    log.Warn(\"dropping unsupported filter, querying unfiltered\", zap.Error(err))\n    params.Filter = nil\n    q, err = toProtoQuery(params)\n}","preventionTips":["Restrict user-supplied filters to operators supported by the api_v3 filter proto","Round-trip test your filter expressions against expressionproto.ToProto in CI","Keep expression library and proto definitions version-aligned"],"tags":["validation","filter-expression","protobuf"],"backgroundTag":"filter-encoding-failed","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}