{"record":{"id":"7318642619714492","repo":"jaegertracing/jaeger","slug":"could-not-convert-sampling-strategy-type-731864","errorCode":null,"errorMessage":"could not convert sampling strategy type","messagePattern":"could not convert sampling strategy type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/converter/thrift/jaeger/sampling_to_domain.go","lineNumber":71,"sourceCode":"\t\t\tProbabilisticSampling: convertProbabilisticToDomain(pos.GetProbabilisticSampling()),\n\t\t}\n\t}\n\treturn &api_v2.PerOperationSamplingStrategies{\n\t\tDefaultSamplingProbability:       s.GetDefaultSamplingProbability(),\n\t\tDefaultUpperBoundTracesPerSecond: s.GetDefaultUpperBoundTracesPerSecond(),\n\t\tDefaultLowerBoundTracesPerSecond: s.GetDefaultLowerBoundTracesPerSecond(),\n\t\tPerOperationStrategies:           poss,\n\t}\n}\n\nfunc convertStrategyTypeToDomain(t sampling.SamplingStrategyType) (api_v2.SamplingStrategyType, error) {\n\tswitch t {\n\tcase sampling.SamplingStrategyType_PROBABILISTIC:\n\t\treturn api_v2.SamplingStrategyType_PROBABILISTIC, nil\n\tcase sampling.SamplingStrategyType_RATE_LIMITING:\n\t\treturn api_v2.SamplingStrategyType_RATE_LIMITING, nil\n\tdefault:\n\t\treturn api_v2.SamplingStrategyType_PROBABILISTIC, errors.New(\"could not convert sampling strategy type\")\n\t}\n}\n","sourceCodeStart":53,"sourceCodeEnd":74,"githubUrl":"https://github.com/jaegertracing/jaeger/blob/806f4447841ecdb60519f408b004a599d515f437/internal/converter/thrift/jaeger/sampling_to_domain.go#L53-L74","documentation":"convertStrategyTypeToDomain returns this error when the legacy Thrift sampling strategy type is neither PROBABILISTIC nor RATE_LIMITING, so it cannot be mapped into the domain model enum. The function returns the zero domain value alongside the error.","triggerScenarios":"ConvertSamplingResponseToDomain receives a sampling.SamplingStrategyType outside the two known enum values — typically a value added by a newer Thrift IDL or a corrupt/unknown wire value; the switch default errors.","commonSituations":"Old/other Jaeger clients sending a strategy type this converter doesn't know; thrift IDL mismatch between the remote client library and the collector's generated code; fuzzed or malformed remote-sampling responses.","solutions":["Ensure the remote client only sends PROBABILISTIC or RATE_LIMITING strategy types","Align the thrift IDL/generated code versions on both sides of the conversion","In the caller, check err != nil and fall back to a default sampling response instead of using the zero-value result"],"exampleFix":"// before\nresp, err := ConvertSamplingResponseToDomain(thriftResp) // thriftResp.StrategyType unknown\n_ = resp // zero-value result used even on error\n// after\nresp, err := ConvertSamplingResponseToDomain(thriftResp)\nif err != nil {\n  resp = defaultSamplingResponse()\n}","handlingStrategy":"type-guard","validationCode":"switch t.StrategyType {\ncase sampling.SamplingStrategyType_PROBABILISTIC, sampling.SamplingStrategyType_RATE_LIMITING:\n    // ok\ndefault:\n    return errors.New(\"unsupported thrift sampling strategy type\")\n}\nresp, err := jaegerconv.ConvertSamplingResponseToDomain(t)","typeGuard":"func convertibleToDomain(t sampling.SamplingStrategyType) bool {\n    return t == sampling.SamplingStrategyType_PROBABILISTIC ||\n        t == sampling.SamplingStrategyType_RATE_LIMITING\n}","tryCatchPattern":"resp, err := ConvertSamplingResponseToDomain(t)\nif err != nil {\n    if strings.Contains(err.Error(), \"could not convert sampling strategy type\") {\n        return defaultDomainResponse(), nil\n    }\n    return nil, err\n}","preventionTips":["Validate incoming thrift strategy type before conversion","Keep thrift IDL versions synchronized with the collector","Ignore the zero-value result when the error is non-nil"],"tags":["go","thrift","sampling","enum","conversion"],"backgroundTag":"unsupported-enum-value","analyzedSha":"806f4447841ecdb60519f408b004a599d515f437","analyzedAt":"2026-09-01T02:39:22.140Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}