apache/beam · error
invalid float encoding for: %v
Error message
invalid float encoding for: %v
What it means
decFloat decodes a byte slice as a zig-zag varuint-encoded, byte-reversed 64-bit float. If the underlying decVarUintZ decode fails (malformed varint: truncated or overlong data), the coder wraps the failure as 'invalid float encoding'. It signals corrupted or mismatched encoded data, not a bad float value.
Source
Thrown at sdks/go/pkg/beam/core/runtime/coderx/float.go:47
func encFloat(v typex.T) []byte {
var val float64
switch n := v.(type) {
case float32:
val = float64(n)
case float64:
val = n
default:
panic(fmt.Sprintf("received unknown value type: want a float, got %T", n))
}
return encVarUintZ(bits.ReverseBytes64(math.Float64bits(val)))
}
func decFloat(t reflect.Type, data []byte) (typex.T, error) {
uval, err := decVarUintZ(reflectx.Uint64, data)
if err != nil {
return nil, errors.Errorf("invalid float encoding for: %v", data)
}
n := math.Float64frombits(bits.ReverseBytes64(uval.(uint64)))
switch t.Kind() {
case reflect.Float64:
return n, nil
case reflect.Float32:
return float32(n), nil
default:
panic(fmt.Sprintf("unreachable statement: expected a float, got %v", t))
}
}
// NewFloat returns a coder for the given float type. It uses the same
// encoding scheme as the gob package.
func NewFloat(t reflect.Type) (*coder.CustomCoder, error) {
switch t.Kind() {
case reflect.Float32, reflect.Float64:View on GitHub (pinned to 12126d8942)
Solutions
- Verify the data was encoded with the same NewFloat coder (encFloat) that is being used to decode.
- Check for truncation or corruption in the source (file, message queue) before decoding.
- Log the offending data bytes to confirm they start with a valid uvarint prefix.
- Re-write the dataset with the current coder if the encoding scheme changed between versions.
Defensive patterns
Strategy: validation
Validate before calling
// validate a buffer before float decode
func validFloatEncoding(data []byte) bool {
_, size := binary.Uvarint(data)
return size > 0 && size <= len(data)
} Type guard
func isFloatCoder(c *coder.CustomCoder) bool { return c.Name == "float" } Try / catch
val, err := customCoder.Decode(data)
if err != nil {
if strings.Contains(err.Error(), "invalid float encoding") {
log.Warnf("skipping corrupt float record: % x", data)
return nil, nil // or route to a dead-letter output
}
return nil, err
} Prevention
- Always pair encFloat/decFloat from the same NewFloat coder instance.
- Include length prefixes when storing encoded floats in streams or files.
- Never mix coder schemes across pipeline versions without a migration.
- Checksum payloads written to durable storage to detect corruption early.
When it happens
Trigger: Calling decFloat (via the 'float' custom coder's Decode) with bytes not produced by encFloat — e.g. decoded with the wrong coder, data truncated, or cross-language coder mismatch.
Common situations: Reading old data written with a different coder scheme, corrupt files/messages, or mixed SDK versions where float encoding differs.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- ReadSimpleRowHeader reading nils count: %v, %v
- invalid varintz encoding for: %v
- invalid varuintz encoding for: %v
- empty type
- ReadSimpleRowHeader expected no nils encoded count, got %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/76bd876388efad41.
Report an issue: GitHub.