{"record":{"id":"7089d35c371bc891","repo":"cayleygraph/cayley","slug":"expected-bool-as-second-argument","errorCode":null,"errorMessage":"expected bool as second argument","messagePattern":"expected bool as second argument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/gizmo/environ.go","lineNumber":199,"sourceCode":"\t\treturn throwErr(vm, fmt.Errorf(\"wildcard: unsupported type: %T\", args[0]))\n\t}\n\treturn vm.ToValue(valFilter{f: shape.Wildcard{Pattern: pattern}})\n}\n\nfunc cmpRegexp(vm *goja.Runtime, call goja.FunctionCall) goja.Value {\n\targs := exportArgs(call.Arguments)\n\tif len(args) != 1 && len(args) != 2 {\n\t\treturn throwErr(vm, errArgCount2{Expected: 1, Got: len(args)})\n\t}\n\tv, err := toQuadValue(args[0])\n\tif err != nil {\n\t\treturn throwErr(vm, err)\n\t}\n\tallowRefs := false\n\tif len(args) > 1 {\n\t\tb, ok := args[1].(bool)\n\t\tif !ok {\n\t\t\treturn throwErr(vm, fmt.Errorf(\"expected bool as second argument\"))\n\t\t}\n\t\tallowRefs = b\n\t}\n\tswitch vt := v.(type) {\n\tcase quad.String:\n\t\tif allowRefs {\n\t\t\tv = quad.IRI(string(vt))\n\t\t}\n\tcase quad.IRI:\n\t\tif !allowRefs {\n\t\t\treturn throwErr(vm, errRegexpOnIRI)\n\t\t}\n\tcase quad.BNode:\n\t\tif !allowRefs {\n\t\t\treturn throwErr(vm, errRegexpOnIRI)\n\t\t}\n\tdefault:\n\t\treturn throwErr(vm, fmt.Errorf(\"regexp: unsupported type: %T\", v))","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/gizmo/environ.go#L181-L217","documentation":"The regexp comparison helper (cmpRegexp) in the Gizmo query environment accepts an optional second argument that controls whether the regexp may match against references (IRIs/BNodes) instead of only plain strings. This argument must be a JavaScript boolean. If a second argument is supplied but is not a boolean, this error is thrown.","triggerScenarios":"Calling regexp(pattern, x) from a Gizmo/JS query where x is a truthy/falsy non-boolean — e.g. regexp(\"^a\", 1), regexp(\"^a\", \"true\"), regexp(\"^a\", null). Omitting the second argument entirely is fine; only providing a wrong-typed one fails.","commonSituations":"Copying examples from other query languages where the flag is 0/1; passing a string \"true\" from templated query construction; confusion with JS truthiness conventions.","solutions":["Pass an actual boolean as the second argument: regexp(\"pattern\", true) or regexp(\"pattern\", false)","Convert numeric/string flags with Boolean(x) or x === 1 before calling","Omit the second argument entirely when only plain strings should be matched"],"exampleFix":"// before\ng.V().Has(\"name\", regexp(\"^Al\", 1))\n// after\ng.V().Has(\"name\", regexp(\"^Al\", true))","handlingStrategy":"validation","validationCode":"function safeRegexp(pattern, allowRefs) {\n  if (allowRefs !== undefined && typeof allowRefs !== \"boolean\")\n    throw new Error(\"second argument to regexp must be a boolean\");\n  return allowRefs === undefined ? regexp(pattern) : regexp(pattern, allowRefs);\n}","typeGuard":"function isBool(v) { return typeof v === \"boolean\"; }","tryCatchPattern":"try {\n  return g.V().Has(\"name\", regexp(pat, flags))\n} catch (e) {\n  if (String(e).includes(\"expected bool as second argument\")) {\n    return g.V().Has(\"name\", regexp(pat, Boolean(flags)))\n  } else { throw e; }\n}","preventionTips":["Use true/false literals, never 0/1 or \"true\"/\"false\" strings","Omit the second argument when default behavior is wanted","Add Boolean() coercion at query-template boundaries"],"tags":["javascript","query","type-error","boolean"],"backgroundTag":"invalid-argument-value","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}