cayleygraph/cayley · error

regexp: unsupported type: %T

Error message

regexp: unsupported type: %T

What it means

In cmpRegexp, the first argument is converted to a quad.Value and then type-switched; only quad.String, quad.IRI, and quad.BNode are valid operands for a regexp value filter. If the converted quad value is any other type (e.g. quad.LangString or quad.Raw/TypedString), this error is thrown reporting the unsupported Go type. It exists because regexp filters can only be evaluated over string-like values.

Source

Thrown at query/gizmo/environ.go:217

			return throwErr(vm, fmt.Errorf("expected bool as second argument"))
		}
		allowRefs = b
	}
	switch vt := v.(type) {
	case quad.String:
		if allowRefs {
			v = quad.IRI(string(vt))
		}
	case quad.IRI:
		if !allowRefs {
			return throwErr(vm, errRegexpOnIRI)
		}
	case quad.BNode:
		if !allowRefs {
			return throwErr(vm, errRegexpOnIRI)
		}
	default:
		return throwErr(vm, fmt.Errorf("regexp: unsupported type: %T", v))
	}
	var (
		s    string
		refs bool
	)
	switch v := v.(type) {
	case quad.String:
		s = string(v)
	case quad.IRI:
		s, refs = string(v), true
	case quad.BNode:
		s, refs = string(v), true
	default:
		return throwErr(vm, fmt.Errorf("regexp from non-string value: %T", v))
	}
	re, err := regexp.Compile(string(s))
	if err != nil {
		return throwErr(vm, err)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Pass a plain string created via str("...") so the value is quad.String
  2. If matching IRI/BNode references, pass iri(...)/bnode(...) and set the second argument to true
  3. Convert or cast the value to a string before applying the regexp filter
  4. Match on a different predicate whose values are plain strings

Example fix

// before
g.V().Has("name", regexp(raw("^Al")))
// after
g.V().Has("name", regexp(str("^Al")))
Defensive patterns

Strategy: type-guard

Validate before calling

function safeRegexpValue(v) {
  // only str(), iri(), bnode() quad values are supported
  return regexp(str(String(v)));
}

Try / catch

try {
  g.V().Has("name", regexp(v))
} catch (e) {
  if (String(e).includes("regexp: unsupported type")) {
    g.V().Has("name", regexp(str(String(v))))
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling regexp(...) in a Gizmo/JS query whose first argument converts to an unsupported quad.Value type — e.g. passing a raw/typed/lang-string value via raw("...") or a typed literal, instead of str(), iri(), or bnode().

Common situations: Matching on values created with raw() or language-tagged literals rather than plain strings; schema changes that switched node values from strings to typed literals; passing objects that toQuadValue maps to non-string quad 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/389b1dfe8bc4e20e. Report an issue: GitHub.