{"record":{"id":"7328467a3e916d20","repo":"apache/beam","slug":"not-a-signed-integer-type-v","errorCode":null,"errorMessage":"not a signed integer type: %v","messagePattern":"not a signed integer type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/coderx/varint.go","lineNumber":35,"sourceCode":"\nimport (\n\t\"encoding/binary\"\n\t\"fmt\"\n\t\"reflect\"\n\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n)\n\n// NewVarIntZ returns a varint coder for the given integer type. It uses a zig-zag scheme,\n// which is _different_ from the Beam standard coding scheme.\nfunc NewVarIntZ(t reflect.Type) (*coder.CustomCoder, error) {\n\tswitch t.Kind() {\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\treturn coder.NewCustomCoder(\"varintz\", t, encVarIntZ, decVarIntZ)\n\tdefault:\n\t\treturn nil, errors.Errorf(\"not a signed integer type: %v\", t)\n\t}\n}\n\n// NewVarUintZ returns a uvarint coder for the given integer type. It uses a zig-zag scheme,\n// which is _different_ from the Beam standard coding scheme.\nfunc NewVarUintZ(t reflect.Type) (*coder.CustomCoder, error) {\n\tswitch t.Kind() {\n\tcase reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:\n\t\treturn coder.NewCustomCoder(\"varuintz\", t, encVarUintZ, decVarUintZ)\n\tdefault:\n\t\treturn nil, errors.Errorf(\"not a unsigned integer type: %v\", t)\n\t}\n}\n\nfunc encVarIntZ(v typex.T) []byte {\n\tvar val int64\n\tswitch n := v.(type) {\n\tcase int:","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/coderx/varint.go#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing uint/uint64 types to the int coder by mistake; generic code paths that don't check Kind before choosing a coder.","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."],"exampleFix":"// before\nc, err := coderx.NewVarIntZ(reflect.TypeOf(uint32(0)))\n// after\nc, err := coderx.NewVarUintZ(reflect.TypeOf(uint32(0)))","handlingStrategy":"type-guard","validationCode":"func canUseVarIntZ(t reflect.Type) bool {\n    switch t.Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n        return true\n    }\n    return false\n}","typeGuard":"func isSignedIntKind(t reflect.Type) bool {\n    k := t.Kind()\n    return k >= reflect.Int && k <= reflect.Int64\n}","tryCatchPattern":"c, err := coderx.NewVarIntZ(t)\nif err != nil {\n    return fmt.Errorf(\"expected signed int type, got %s: %w\", t, err)\n}","preventionTips":["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."],"tags":["go","apache-beam","coder","type-mismatch","reflect"],"backgroundTag":"incompatible-source-type","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}