hyperledger/fabric · error
unsupported slice type %v for field %s
Error message
unsupported slice type %v for field %s
What it means
The serializer supports only string, int64, []byte (uint8 slice), and proto pointer fields. If a struct field is a slice whose element type is not uint8 (e.g. []string, []int64), SerializableChecks rejects it with this error naming the element kind and field name.
Source
Thrown at core/chaincode/lifecycle/serializer.go:98
return reflect.Value{}, nil, errors.Errorf("must be pointer to struct, but got non-pointer %v", value.Kind())
}
value = value.Elem()
if value.Kind() != reflect.Struct {
return reflect.Value{}, nil, errors.Errorf("must be pointers to struct, but got pointer to %v", value.Kind())
}
allFields := make([]string, value.NumField())
for i := 0; i < value.NumField(); i++ {
fieldName := value.Type().Field(i).Name
fieldValue := value.Field(i)
allFields[i] = fieldName
switch fieldValue.Kind() {
case reflect.String:
case reflect.Int64:
case reflect.Slice:
if fieldValue.Type().Elem().Kind() != reflect.Uint8 {
return reflect.Value{}, nil, errors.Errorf("unsupported slice type %v for field %s", fieldValue.Type().Elem().Kind(), fieldName)
}
case reflect.Pointer:
if !fieldValue.Type().Implements(ProtoMessageType) {
return reflect.Value{}, nil, errors.Errorf("unsupported pointer type %v for field %s (must be proto)", fieldValue.Type().Elem(), fieldName)
}
default:
return reflect.Value{}, nil, errors.Errorf("unsupported structure field kind %v for serialization for field %s", fieldValue.Kind(), fieldName)
}
}
return value, allFields, nil
}
// Serialize takes a pointer to a struct, and writes each of its fields as keys
// into a namespace. It also writes the struct metadata (if it needs updating)
// and, deletes any keys in the namespace which are not found in the struct.
// Note: If a key already exists for the field, and the value is unchanged, then
// the key is _not_ written to.
func (s *Serializer) Serialize(namespace, name string, structure any, state ReadWritableState) error {View on GitHub (pinned to 2736b63f8f)
Solutions
- Change the field to []byte and encode lists with json.Marshal or proto.Marshal before serializing
- Use a proto pointer field holding a repeated-field message instead of a Go slice
- Re-check the struct against the supported kinds: string, int64, []byte, proto pointer
Example fix
// before
type Def struct { Peers []string }
// after
type Def struct { Peers []byte } // json.Marshal([]string{...}) into bytes Defensive patterns
Strategy: validation
Validate before calling
func noNonByteSlices(v any) error {
rv := reflect.ValueOf(v).Elem()
t := rv.Type()
for i := 0; i < t.NumField(); i++ {
f := t.Field(i).Type
if f.Kind() == reflect.Slice && f.Elem().Kind() != reflect.Uint8 {
return fmt.Errorf("field %s: only []byte slices supported", t.Field(i).Name)
}
}
return nil
} Type guard
func isByteSlice(f reflect.Type) bool { return f.Kind() == reflect.Slice && f.Elem().Kind() == reflect.Uint8 } Try / catch
_, _, err := s.SerializableChecks(input)
if err != nil && strings.Contains(err.Error(), "unsupported slice type") {
// encode the slice as []byte and retry
} Prevention
- Keep state structs limited to string/int64/[]byte/proto pointer fields
- Encode lists with json.Marshal or proto messages before persisting
- Lint/validate new struct fields against the supported kinds
When it happens
Trigger: Defining a lifecycle state struct with fields like []string, []uint64, [][]byte and calling Serialize/IsSerialized/Deserialize on it.
Common situations: Adding a list of peer addresses/endorsements ([]string) to a chaincode metadata struct; modeling repeated proto fields as Go slices in state structs.
Related errors
- unsupported structure field kind %v for serialization for fi
- unsupported pointer type %v for field %s (must be proto)
- unsupported policy type %T on channel '%s'
- proto: Marshal called with nil
- must be pointer to struct, but got non-pointer %v
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/0d15af2cf42a3030.
Report an issue: GitHub.