{"record":{"id":"f9bc65a6a5be3710","repo":"cayleygraph/cayley","slug":"unexpected-type-for-id-t","errorCode":null,"errorMessage":"Unexpected type for @id %T","messagePattern":"Unexpected type for @id %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/linkedql/steps/match.go","lineNumber":142,"sourceCode":"\tpatternClone := linkedql.GraphPattern{\n\t\t\"@context\": context,\n\t}\n\tfor key, value := range pattern {\n\t\tpatternClone[key] = value\n\t}\n\treturn pattern\n}\n\nfunc quadsFromMap(o interface{}) ([]quad.Quad, error) {\n\treader := jsonld.NewReaderFromMap(o)\n\treturn quad.ReadAll(reader)\n}\n\nfunc normalizeQuads(quads []quad.Quad, pattern linkedql.GraphPattern) ([]quad.Quad, error) {\n\tif id, ok := pattern[\"@id\"]; ok && len(quads) == 0 {\n\t\tidString, ok := id.(string)\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"Unexpected type for @id %T\", idString)\n\t\t}\n\t\tquads = append(quads, makeSingleEntityQuad(quad.IRI(idString)))\n\t}\n\treturn quads, nil\n}\n\nfunc parsePattern(pattern linkedql.GraphPattern, ns *voc.Namespaces) ([]quad.Quad, error) {\n\tcontextualizedPattern := contextualizePattern(pattern, ns)\n\tquads, err := quadsFromMap(contextualizedPattern)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tquads, err = normalizeQuads(quads, contextualizedPattern)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(quads) == 0 && len(pattern) != 0 {\n\t\treturn nil, fmt.Errorf(\"Pattern does not parse to any quad. `{}` is the only pattern allowed to not parse to any quad\")","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/linkedql/steps/match.go#L124-L160","documentation":"normalizeQuads in match.go:142 inspects a Match pattern's \"@id\" field to synthesize a single-entity quad when the pattern produces no quads of its own. If the \"@id\" value is not a Go string, this error is thrown (note: the message prints idString's type, which equals id's type). It indicates the pattern's @id was supplied as a non-string JSON value.","triggerScenarios":"Building a linkedql Match / GraphPattern with \"@id\" set to a number, bool, map, or slice instead of a string, e.g. via unmarshalled JSON where @id was numeric.","commonSituations":"Programmatic pattern construction with the wrong Go type, or JSON queries where @id was written unquoted.","solutions":["Set the pattern's @id to a plain string IRI.","If @id comes from user JSON, coerce/validate it as string before constructing the GraphPattern.","Check the %T in the message to identify which wrong type was supplied."],"exampleFix":"// before\npattern := linkedql.GraphPattern{\"@id\": 42}\n// after\npattern := linkedql.GraphPattern{\"@id\": \"http://example.org/entity/42\"}","handlingStrategy":"validation","validationCode":"id, ok := pattern[\"@id\"]\nif ok {\n  if _, isStr := id.(string); !isStr {\n    return fmt.Errorf(\"@id must be a string, got %T\", id)\n  }\n}","typeGuard":"func idString(pattern map[string]interface{}) (string, bool) {\n  id, ok := pattern[\"@id\"]\n  if !ok { return \"\", false }\n  s, ok := id.(string)\n  return s, ok\n}","tryCatchPattern":"quads, err := parsePattern(pattern, ctx)\nif err != nil {\n  if strings.Contains(err.Error(), \"Unexpected type for @id\") {\n    // fix pattern construction: @id must be string\n  }\n  return err\n}","preventionTips":["Always assign string IRIs to @id","Validate user-supplied JSON so @id is coerced to string or rejected early","Use typed constructors for GraphPattern fields where available"],"tags":["linkedql","jsonld","type-mismatch","go"],"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"}