You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## What changed?
Follow up to #7761:
1. Use more concrete types instead of `comparable`.
2. Use `softassert` for "compile" time errors.
3. Rename `chasm.Collection` to `chasm.Map` but left proto
`CollectionAttributes` intact. This will allow to add support for other
collection type in future (slice, array).
## Why?
It is better to narrow key type as much as possible. Other types are not
supported anyway.
## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
fieldErr=serviceerror.NewInternalf("%s.%s: unsupported field type %s: must implement proto.Message, or be chasm.Field[T] or chasm.Collection[T]", valueT, fieldN, fieldT)
67
+
fieldErr=serviceerror.NewInternalf("%s.%s: unsupported field type %s: must implement proto.Message, or be chasm.Field[T] or chasm.Map[T]", valueT, fieldN, fieldT)
returnserviceerror.NewInternalf("CHASM collection must be of map[comparable]Field[T] type: %s map value type is not Field[T] but %s", n.nodeName, collectionValT)
return"", serviceerror.NewInternalf("CHASM collection must be of map[comparable|string]Field[T] type: %s map key type not comparable but %s", nodeName, keyV.Type().String())
633
+
errMsg:=fmt.Sprintf("CHASM map key type for node %s must be one of [%s], got %s", n.nodeName, mapKeyTypes, keyV.Type().String())
634
+
softassert.Fail(n.logger, errMsg)
635
+
return"", serviceerror.NewInternal(errMsg)
630
636
}
631
637
}
632
638
633
-
funcstringToComparableKey(nodeNamestring, keystring, keyT reflect.Type) (reflect.Value, error) {
639
+
func(n*Node) stringToMapKey(nodeNamestring, keystring, keyT reflect.Type) (reflect.Value, error) {
err=fmt.Errorf("unsupported type %s of kind %s", keyT.String(), keyT.Kind().String())
692
+
err=fmt.Errorf("unsupported type %s of kind %s: supported key types: %s", keyT.String(), keyT.Kind().String(), mapKeyTypes)
693
+
softassert.Fail(n.logger, err.Error())
694
+
// Use softassert only here because this is the only case that indicates "compile" time error.
695
+
// The other errors below can come from data type mismatch between a component and persisted data.
687
696
}
688
697
689
698
iferr==nil&&!keyV.IsValid() {
690
699
err=fmt.Errorf("value %s is not valid of type %s of kind %s", key, keyT.String(), keyT.Kind().String())
691
700
}
692
701
693
702
iferr!=nil {
694
-
err=serviceerror.NewInternalf("serialized collection %s key value %s can't be parsed to CHASM collection key type %s: %s", nodeName, key, keyT.String(), err.Error())
703
+
err=serviceerror.NewInternalf("serialized map %s key value %s can't be parsed to CHASM map key type %s: %s", nodeName, key, keyT.String(), err.Error())
0 commit comments