cayleygraph/cayley · error

errNoVia

errNoVia

Error message

expected predicate list

What it means

errNoVia is returned when a traversal method that requires a via argument (inout, Both, FollowRecursive, LabelContext) receives arguments that toViaData cannot interpret as a predicate list. toViaData returns ok=false when no predicates/tags can be extracted, and the caller surfaces this error through the VM instead of panicking.

Source

Thrown at query/gizmo/errors.go:20

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package gizmo

import "fmt"

var (
	errNoVia       = fmt.Errorf("expected predicate list")
	errRegexpOnIRI = fmt.Errorf("regexps are not allowed on IRIs")
)

type errArgCount2 struct {
	Expected int
	Got      int
}

func (e errArgCount2) Error() string {
	return fmt.Sprintf("expected %d argument, got %d", e.Expected, e.Got)
}

type errArgCount struct {
	Got int
}

func (e errArgCount) Error() string {
	return fmt.Sprintf("unexpected arguments count: %d", e.Got)

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Supply at least one predicate: p.Both("knows") or a path p.Both(g.V("<alice").out("knows")).
  2. Ensure arguments are strings, arrays of strings, or path objects — not plain objects or numbers.
  3. If the traversal genuinely needs 'any', use a wildcard predicate as supported by the API rather than omitting via.

Example fix

// before
p.Both().all()
// after
p.Both("knows").all()
Defensive patterns

Strategy: validation

Validate before calling

if (!preds || (Array.isArray(preds) && preds.length === 0)) throw new Error('Both/inout requires at least one predicate');

Type guard

function hasVia(args) { return args.length > 0 && (typeof args[0] === 'string' || Array.isArray(args[0]) || args[0] instanceof mori.Path); }

Try / catch

try { p.Both("knows").all(); } catch (e) { if (String(e).includes('expected predicate list')) { /* fix args */ } throw e; }

Prevention

When it happens

Trigger: Calling p.Both() or p.Inout() with no arguments, or with arguments that are not predicates/paths/strings (e.g. a bare object), so exportArgs/toViaData yields ok=false at traversals.go:112 (Both) or :197 (inout path).

Common situations: Handwritten gizmo scripts missing the predicate argument after refactors, or passing JS values (numbers, booleans) where predicate names are expected.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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