cayleygraph/cayley · error

unsupported type: %T

Error message

unsupported type: %T

What it means

toVia normalizes a via argument list so each element becomes a path, *pathObject, or a quad value; when an element cannot be converted by toQuadValue and is not a path-like object, it panics with "unsupported type". This is gizmo's guard that traversal 'via' arguments are predicates, paths, or plain query values.

Source

Thrown at query/gizmo/environ.go:394

		} else if v, ok := via[0].([]interface{}); ok {
			return toVia(v)
		} else if v, ok := via[0].([]string); ok {
			arr := make([]interface{}, 0, len(v))
			for _, s := range v {
				arr = append(arr, s)
			}
			return toVia(arr)
		}
	}
	for i := range via {
		if _, ok := via[i].(*path.Path); ok {
			// bypass
		} else if vp, ok := via[i].(*pathObject); ok {
			via[i] = vp.path
		} else if qv, err := toQuadValue(via[i]); err == nil {
			via[i] = qv
		} else {
			panic(fmt.Errorf("unsupported type: %T", via[i]))
		}
	}
	return via
}

func toViaData(objs []interface{}) (predicates []interface{}, tags []string, ok bool) {
	if len(objs) != 0 {
		predicates = toVia([]interface{}{objs[0]})
	}
	if len(objs) > 1 {
		tags = toStrings(objs[1:])
	}
	ok = true
	return
}

func toViaDepthData(objs []interface{}) (predicates []interface{}, maxDepth int, tags []string, ok bool) {
	if len(objs) != 0 {

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Pass a string predicate, a *pathObject (result of g.V(...)/p.out(...)), or a simple scalar value for via.
  2. Check the %T in the panic to see the offending type and convert it (e.g. .toString() in JS or quad value on the Go side).
  3. For composite conditions build a proper path expression instead of raw objects.

Example fix

// before
p.Both({pred: "knows"})
// after
p.Both("knows")
Defensive patterns

Strategy: type-guard

Validate before calling

const isValidVia = v => typeof v === 'string' || v instanceof mori.Path || ['string','number','boolean'].includes(typeof v);
if (!viaArgs.every(isValidVia)) throw new Error('unsupported via element');

Type guard

function isPathLike(v) { return v instanceof mori.Path || typeof v === 'string'; }

Prevention

When it happens

Trigger: Passing a via element of an unsupported Go/JS type — e.g. a function, undefined/null, nested pathObject inside a deep structure, or a goja object with no quad representation — into pathObject.Via-derived code paths (Both/FollowRecursive via toViaData/toViaDepthData).

Common situations: Gizmo scripts passing JS objects or functions as predicates (e.g. .both({a:1})), or API users embedding values like maps that have no quad equivalent.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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