{"record":{"id":"93a2d095f48211e3","repo":"cayleygraph/cayley","slug":"expected-v-to-be-a-map-or-a-slice-with-a-single","errorCode":null,"errorMessage":"Expected %#v to be a map or a slice with a single map but instead received %T","messagePattern":"Expected %#v to be a map or a slice with a single map but instead received %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/linkedql/steps/jsonld_util.go","lineNumber":67,"sourceCode":"\t\t\treturn fmt.Errorf(\"Expected multiple values but instead received the single value: %#v\", target)\n\t\t}\n\t\tif len(s) != len(t) {\n\t\t\treturn fmt.Errorf(\"Expected %#v and %#v to have the same length\", s, t)\n\t\t}\n\titems:\n\t\tfor _, i := range s {\n\t\t\tfor _, tI := range t {\n\t\t\t\tif isomorphic(i, tI) == nil {\n\t\t\t\t\tcontinue items\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"No matching values for the item %#v in %#v\", i, t)\n\t\t}\n\t\treturn nil\n\tcase ldMap:\n\t\tt, ok := target.(ldMap)\n\t\tif !ok {\n\t\t\treturn fmt.Errorf(\"Expected %#v to be a map or a slice with a single map but instead received %T\", target, target)\n\t\t}\n\t\tfor k, v := range s {\n\t\t\ttV, _ := t[k]\n\t\t\terr := isomorphic(v, tV)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":79,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/linkedql/steps/jsonld_util.go#L49-L79","documentation":"In jsonld_util.go:67, when the isomorphic comparison reaches a source ldMap it requires the target to also be an ldMap. If the target value is neither a map nor a slice containing a single map, this error is thrown with the target's Go type (%T). It signals a structural mismatch between the pattern object and the value it is compared against.","triggerScenarios":"Calling isomorphic with source = map value and target = a non-map, non-single-map-slice value (e.g. a string, number, or empty slice), typically via a malformed JSON-LD pattern.","commonSituations":"Hand-written JSON-LD patterns where an object is placed where a scalar is expected in the reference data (or vice versa); unmarshalling quirks producing slices instead of maps.","solutions":["Ensure both sides of the comparison are JSON objects where objects are expected.","Inspect the %T value in the message to see the actual Go type of the mismatching target.","If the target should be a single-element slice, wrap the map accordingly or fix the producer of the data.","Validate the JSON-LD pattern shape before passing it to pattern parsing."],"exampleFix":"// before\nisomorphic(map[string]interface{}{\"@id\": \"x\"}, \"not-a-map\")\n// after\nisomorphic(map[string]interface{}{\"@id\": \"x\"}, map[string]interface{}{\"@id\": \"x\"})","handlingStrategy":"type-guard","validationCode":"func isLDMapOrSingleMapSlice(v interface{}) bool {\n  if _, ok := v.(map[string]interface{}); ok { return true }\n  if s, ok := v.([]interface{}); ok { return len(s) == 1 }\n  return false\n}","typeGuard":"func asLDMap(v interface{}) (map[string]interface{}, bool) {\n  if m, ok := v.(map[string]interface{}); ok { return m, true }\n  if s, ok := v.([]interface{}); ok && len(s) == 1 {\n    if m, ok := s[0].(map[string]interface{}); ok { return m, true }\n  }\n  return nil, false\n}","tryCatchPattern":"if err := isomorphic(src, target); err != nil {\n  var te *typeMismatchError // or inspect err.Error() for %T info\n  log.Printf(\"structural mismatch during isomorphic: %v\", err)\n}","preventionTips":["Keep pattern and document shapes aligned: objects where objects are expected","Validate JSON-LD with a schema before comparison","Decode JSON with map[string]interface{} target types to avoid odd intermediate types"],"tags":["jsonld","type-mismatch","linkedql","go"],"backgroundTag":"type-mismatch","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}