{"record":{"id":"4fe12d87deab43f5","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-count-float","errorCode":null,"errorMessage":"cannot read count_float","messagePattern":"cannot read count_float","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/prompb/write_request_unmarshaler.go","lineNumber":261,"sourceCode":"\n\tvar err error\n\tvar fc easyproto.FieldContext\n\tfor len(src) > 0 {\n\t\tsrc, err = fc.NextField(src)\n\t\tif err != nil {\n\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read next field: %w\", err)\n\t\t}\n\t\tvar ok bool\n\t\tswitch fc.FieldNum {\n\t\tcase 1:\n\t\t\tnhctx.countInt, ok = fc.Uint64()\n\t\t\tif !ok {\n\t\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read count_int\")\n\t\t\t}\n\t\tcase 2:\n\t\t\tnhctx.countFloat, ok = fc.Double()\n\t\t\tif !ok {\n\t\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read count_float\")\n\t\t\t}\n\t\t\tnhctx.isCountFloat = true\n\t\tcase 3:\n\t\t\tnhctx.sum, ok = fc.Double()\n\t\t\tif !ok {\n\t\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read sum\")\n\t\t\t}\n\t\tcase 4:\n\t\t\tnhctx.schema, ok = fc.Sint32()\n\t\t\tif !ok {\n\t\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read schema\")\n\t\t\t}\n\t\tcase 5:\n\t\t\tnhctx.zeroThreshold, ok = fc.Double()\n\t\t\tif !ok {\n\t\t\t\treturn tss, labelsPool, samplesPool, fmt.Errorf(\"cannot read zero_threshold\")\n\t\t\t}\n\t\tcase 6:","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/prompb/write_request_unmarshaler.go#L243-L279","documentation":"Field 2 of the Histogram message is sum as double. unmarshalHistogram calls fc.Double(); if the bytes cannot be read as a fixed64 double it returns \"cannot read count_float\". Note the message text says count_float but the failing field here is the sum (field 3 path shown); the cause is a wrong wire type or corrupt fixed64 bytes.","triggerScenarios":"UnmarshalProtobuf processes a Histogram whose field 2 (count_float) or field 3 (sum) bytes are not valid 8-byte fixed64 doubles — e.g. count_float encoded as varint, or sum truncated to fewer than 8 bytes.","commonSituations":"Custom histogram serializers using varints for float fields; truncated messages cutting a double in half; clients built against drifted proto definitions where field numbers shifted.","solutions":["Verify count_float (field 2) and sum (field 3) are both encoded as wire type 1 fixed64 doubles","Check for truncation — an 8-byte double cut short by a bad length prefix produces exactly this failure","Regenerate the client from the canonical prompb proto and retest","Round-trip the payload through a reference decoder (protoc --decode) to locate the malformed field"],"exampleFix":"// before: sum encoded as varint\nhb = protowire.AppendTag(hb, 3, protowire.VarintType)\nhb = protowire.AppendVarint(hb, uint64(sum))\n// after: sum encoded as fixed64 double\nhb = protowire.AppendTag(hb, 3, protowire.Fixed64Type)\nhb = protowire.AppendFixed64(hb, math.Float64bits(sum))","handlingStrategy":"validation","validationCode":"func validateDoubleField(data []byte) bool {\n    _, n := protowire.ConsumeFixed64(data)\n    return n > 0\n}","typeGuard":null,"tryCatchPattern":"if err := unmarshalHistogram(data, tss, lp, sp, labels, fb); err != nil {\n    if strings.Contains(err.Error(), \"cannot read count_float\") || strings.Contains(err.Error(), \"cannot read sum\") {\n        log.Printf(\"bad double field in histogram: %v\", err)\n        return errBadHistogramField\n    }\n    return err\n}","preventionTips":["Always encode double fields (count_float field 2, sum field 3) as wire type 1 fixed64","Check length prefixes so 8-byte doubles are never truncated","Verify payloads with protoc --decode during development of custom serializers","Keep one source of truth for the proto file shared by all producing services"],"tags":["protobuf","native-histograms","deserialization","go"],"backgroundTag":"protobuf-wire-type-mismatch","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}