Copilot commented on code in PR #3505:
URL: https://github.com/apache/dubbo-go/pull/3505#discussion_r3717988887
##########
filter/generic/generalizer/map.go:
##########
@@ -68,7 +68,15 @@ func (g *MapGeneralizer) Realize(obj any, typ reflect.Type)
(any, error) {
obj = removeClass(obj)
}
newobj := reflect.New(typ).Interface()
- err := mapstructure.Decode(obj, newobj)
+ decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
+ Result: newobj,
+ TagName: "m",
+ })
+ if err != nil {
+ return nil, perrors.Errorf("realizing map failed, %v", err)
+ }
Review Comment:
This error message is the same as the later decode failure and doesn’t
indicate the stage that failed. Consider making it more specific (e.g.,
'creating map decoder failed: ...') so operational logs clearly show whether
failure happened during decoder construction vs decoding.
##########
filter/generic/generalizer/map_test.go:
##########
@@ -71,6 +76,21 @@ func TestObjToMap(t *testing.T) {
assert.Equal(t, 100, m["eeEe"].(int))
}
+func TestMTagRoundTrip(t *testing.T) {
+ original := testMTagObj{
+ UserID: "42",
+ Name: "alice",
+ }
+
+ generalized, err := mockMapGeneralizer.Generalize(original)
+ require.NoError(t, err)
+ assert.Equal(t, "42", generalized.(map[string]any)["user_id"])
Review Comment:
The direct type assertion `generalized.(map[string]any)` will panic if
`Generalize` ever returns a different map type (e.g., `map[string]interface{}`
vs `map[string]any` in some paths, or a non-map). Prefer asserting the type
safely (e.g., `m, ok := generalized.(map[string]any)` + `require.True`, or
`require.IsType`) so failures report cleanly without panicking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]