apache/beam · error
not a signed integer type: %v
Error message
not a signed integer type: %v
What it means
NewVarIntZ creates a zig-zag varint custom coder, valid only for signed integer kinds (int, int8, int16, int32, int64). Any other kind — unsigned ints, floats, strings, structs — yields this error at construction time.
Source
Thrown at sdks/go/pkg/beam/core/runtime/coderx/varint.go:35
import (
"encoding/binary"
"fmt"
"reflect"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
)
// NewVarIntZ returns a varint coder for the given integer type. It uses a zig-zag scheme,
// which is _different_ from the Beam standard coding scheme.
func NewVarIntZ(t reflect.Type) (*coder.CustomCoder, error) {
switch t.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return coder.NewCustomCoder("varintz", t, encVarIntZ, decVarIntZ)
default:
return nil, errors.Errorf("not a signed integer type: %v", t)
}
}
// NewVarUintZ returns a uvarint coder for the given integer type. It uses a zig-zag scheme,
// which is _different_ from the Beam standard coding scheme.
func NewVarUintZ(t reflect.Type) (*coder.CustomCoder, error) {
switch t.Kind() {
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return coder.NewCustomCoder("varuintz", t, encVarUintZ, decVarUintZ)
default:
return nil, errors.Errorf("not a unsigned integer type: %v", t)
}
}
func encVarIntZ(v typex.T) []byte {
var val int64
switch n := v.(type) {
case int:View on GitHub (pinned to 12126d8942)
Solutions
- Use NewVarUintZ for unsigned integer kinds instead.
- Pass a signed integer type such as reflect.TypeOf(int64(0)).
- Add a Kind() switch in generic coder-selection code to route to the correct coder constructor.
Example fix
// before c, err := coderx.NewVarIntZ(reflect.TypeOf(uint32(0))) // after c, err := coderx.NewVarUintZ(reflect.TypeOf(uint32(0)))
Defensive patterns
Strategy: type-guard
Validate before calling
func canUseVarIntZ(t reflect.Type) bool {
switch t.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return true
}
return false
} Type guard
func isSignedIntKind(t reflect.Type) bool {
k := t.Kind()
return k >= reflect.Int && k <= reflect.Int64
} Try / catch
c, err := coderx.NewVarIntZ(t)
if err != nil {
return fmt.Errorf("expected signed int type, got %s: %w", t, err)
} Prevention
- Pick NewVarIntZ vs NewVarUintZ based on t.Kind(), never on the variable's name or intent.
- Centralize coder selection in one helper that switches on Kind.
- Add unit tests for coder registration covering each schema field type.
When it happens
Trigger: Calling coderx.NewVarIntZ(t) with an unsigned integer, float, or non-numeric reflect.Type; also via inferCoder/intCoder when a field's kind is not signed-integer.
Common situations: Passing uint/uint64 types to the int coder by mistake; generic code paths that don't check Kind before choosing a coder.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- not a float type: %v
- not a unsigned integer type: %v
- received unknown value type: want []byte, got %T
- coder type %v must be identical to node type %v
- GroupByKey requires its input to use KvCoder
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/7328467a3e916d20.
Report an issue: GitHub.