cayleygraph/cayley · warning

regexp from non-string value: %T

Error message

regexp from non-string value: %T

What it means

After cmpRegexp validates that the value is a string-like quad type, a second switch converts it to the pattern string. This default branch is a defensive invariant check: since the first switch already rejected non-string-like types, reaching it means the value type still isn't quad.String, quad.IRI, or quad.BNode when compiling the regexp. The error names the offending type.

Source

Thrown at query/gizmo/environ.go:231

		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)
	}
	return vm.ToValue(valFilter{f: shape.Regexp{Re: re, Refs: refs}})
}

type valFilter struct {
	f shape.ValueFilter
}

var defaultEnv = map[string]func(vm *goja.Runtime, call goja.FunctionCall) goja.Value{
	"iri":   oneStringType(func(s string) quad.Value { return quad.IRI(s) }),
	"bnode": oneStringType(func(s string) quad.Value { return quad.BNode(s) }),
	"raw":   oneStringType(func(s string) quad.Value { return quad.Raw(s) }),
	"str":   oneStringType(func(s string) quad.Value { return quad.String(s) }),

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Update both type switches in cmpRegexp to handle the new quad.Value type consistently
  2. Ensure any value reaching regexp compilation is quad.String, quad.IRI, or quad.BNode
  3. Check for recent changes to toQuadValue or quad package types that added variants

Example fix

// before
default:
    return throwErr(vm, fmt.Errorf("regexp from non-string value: %T", v))
// after
case quad.TypedString:
    s, refs = string(v), false
default:
    return throwErr(vm, fmt.Errorf("regexp from non-string value: %T", v))
Defensive patterns

Strategy: try-catch

Try / catch

try {
  g.V().Has("name", regexp(v))
} catch (e) {
  log(String(e)); // includes "regexp from non-string value" — report as a bug if hit
}

Prevention

When it happens

Trigger: Practically unreachable through normal cmpRegexp input; could only occur if toQuadValue or the preceding switch logic changes (e.g. a new quad.Value type added and only one of the two switches updated), or via an allowRefs conversion path producing an unexpected type.

Common situations: Developers extending environ.go with new quad value types but updating only one type switch; custom quad.Value implementations reaching the regexp filter path.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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