cayleygraph/cayley · error

array fields are not supported yet

Error message

array fields are not supported yet

What it means

Schema generation walks struct fields via reflection and only supports pointer/slice-wrapped scalars and structs. Fixed-size arrays (reflect.Array) are explicitly unsupported, so Generate fails when it encounters one. There is a TODO in the source to add array support.

Source

Thrown at schema/schema.go:209

		}
	}
	if ps == "" {
		return nil, fmt.Errorf("wrong quad format: '%s': no predicate", rule)
	}
	p := c.toIRI(ps)
	if vs == "" || vs == any && fld.Type != reflEmptyStruct {
		return saveRule{Pred: p, Rev: rev, Opt: opt}, nil
	}
	return constraintRule{Pred: p, Val: c.toIRI(vs), Rev: rev}, nil
}

func checkFieldType(ftp reflect.Type) error {
	for ftp.Kind() == reflect.Ptr || ftp.Kind() == reflect.Slice {
		ftp = ftp.Elem()
	}
	switch ftp.Kind() {
	case reflect.Array: // TODO: support arrays
		return fmt.Errorf("array fields are not supported yet")
	case reflect.Func, reflect.Invalid:
		return fmt.Errorf("%v fields are not supported", ftp.Kind())
	default:
	}
	return nil
}

var (
	typesMu   sync.RWMutex
	typeToIRI = make(map[reflect.Type]quad.IRI)
	iriToType = make(map[quad.IRI]reflect.Type)
)

func getTypeIRI(rt reflect.Type) quad.IRI {
	typesMu.RLock()
	iri := typeToIRI[rt]
	typesMu.RUnlock()
	return iri

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Change the field to a slice ([]T) instead of a fixed array
  2. Exclude the field from schema with the appropriate ignore tag (e.g. `quad:"-"`)
  3. Convert the array to a supported type before calling Generate, or wrap it in a custom struct

Example fix

// before
type Doc struct {
    Hash [32]byte
}
// after
type Doc struct {
    Hash []byte
}
Defensive patterns

Strategy: validation

Validate before calling

func hasArrayField(v interface{}) bool {
    t := reflect.TypeOf(v)
    if t.Kind() == reflect.Ptr { t = t.Elem() }
    for i := 0; i < t.NumField(); i++ {
        ft := t.Field(i).Type
        for ft.Kind() == reflect.Ptr || ft.Kind() == reflect.Slice { ft = ft.Elem() }
        if ft.Kind() == reflect.Array { return true }
    }
    return false
}

Try / catch

if err := schema.Generate(c, Person{}); err != nil {
    if strings.Contains(err.Error(), "array fields are not supported") {
        // convert field to slice or ignore it
    }
    return err
}

Prevention

When it happens

Trigger: Calling Generate on a struct that contains a field of type [N]T, e.g. [4]byte or [2]string.

Common situations: Models with fixed-size binary hashes, coordinate tuples, or fixed buffers declared as arrays instead of slices.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/941088c49ba6fdb3. Report an issue: GitHub.