cayleygraph/cayley · error
Expected %#v to be a map or a slice with a single map but in
Error message
Expected %#v to be a map or a slice with a single map but instead received %T
What it means
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.
Source
Thrown at query/linkedql/steps/jsonld_util.go:67
return fmt.Errorf("Expected multiple values but instead received the single value: %#v", target)
}
if len(s) != len(t) {
return fmt.Errorf("Expected %#v and %#v to have the same length", s, t)
}
items:
for _, i := range s {
for _, tI := range t {
if isomorphic(i, tI) == nil {
continue items
}
}
return fmt.Errorf("No matching values for the item %#v in %#v", i, t)
}
return nil
case ldMap:
t, ok := target.(ldMap)
if !ok {
return fmt.Errorf("Expected %#v to be a map or a slice with a single map but instead received %T", target, target)
}
for k, v := range s {
tV, _ := t[k]
err := isomorphic(v, tV)
if err != nil {
return err
}
}
}
return nil
}
View on GitHub (pinned to 81dcd7d73e)
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.
Example fix
// before
isomorphic(map[string]interface{}{"@id": "x"}, "not-a-map")
// after
isomorphic(map[string]interface{}{"@id": "x"}, map[string]interface{}{"@id": "x"}) Defensive patterns
Strategy: type-guard
Validate before calling
func isLDMapOrSingleMapSlice(v interface{}) bool {
if _, ok := v.(map[string]interface{}); ok { return true }
if s, ok := v.([]interface{}); ok { return len(s) == 1 }
return false
} Type guard
func asLDMap(v interface{}) (map[string]interface{}, bool) {
if m, ok := v.(map[string]interface{}); ok { return m, true }
if s, ok := v.([]interface{}); ok && len(s) == 1 {
if m, ok := s[0].(map[string]interface{}); ok { return m, true }
}
return nil, false
} Try / catch
if err := isomorphic(src, target); err != nil {
var te *typeMismatchError // or inspect err.Error() for %T info
log.Printf("structural mismatch during isomorphic: %v", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Unexpected type for @id %T
- No matching values for the item %#v in %#v
- Unexpected type
- must execute a Step
- must execute a IteratorStep or PathStep
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/93a2d095f48211e3.
Report an issue: GitHub.