cayleygraph/cayley · error

%v fields are not supported

Error message

%v fields are not supported

What it means

checkFieldType rejects field types the schema generator cannot serialize: reflect.Func and reflect.Invalid kinds. The error message names the offending kind. It fires after unwrapping pointers and slices down to the element type.

Source

Thrown at schema/schema.go:211

	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. Remove or ignore the func/invalid-typed field from schema mapping (tag it out, e.g. `quad:"-"`)
  2. Move function fields out of the data struct into a separate runtime-only struct
  3. Ensure interface-typed fields have a concrete, serializable type before Generate

Example fix

// before
type Doc struct {
    OnSave func()
}
// after
type Doc struct {
    OnSave func() `quad:"-"`
}
Defensive patterns

Strategy: validation

Validate before calling

func hasFuncField(v interface{}) bool {
    t := reflect.TypeOf(v)
    if t.Kind() == reflect.Ptr { t = t.Elem() }
    for i := 0; i < t.NumField(); i++ {
        k := t.Field(i).Type.Kind()
        if k == reflect.Func || k == reflect.Invalid { return true }
    }
    return false
}

Try / catch

if err := schema.Generate(c, Doc{}); err != nil {
    if strings.Contains(err.Error(), "fields are not supported") {
        // remove/ignore the offending func field
    }
    return err
}

Prevention

When it happens

Trigger: Calling Generate on a struct containing a func-typed field, or a nil/invalid reflect.Type reaching field inspection (e.g. interface{} fields resolving to invalid, or slice of untyped nil).

Common situations: Structs embedding callbacks, closures, or injected handler functions; fields of interface type whose element type is invalid; reflection bugs producing zero types.

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/45130b98d959c722. Report an issue: GitHub.