Copilot commented on code in PR #3417:
URL: https://github.com/apache/dubbo-go/pull/3417#discussion_r3417591091


##########
cluster/router/script/router.go:
##########
@@ -72,7 +72,8 @@ func (s *ScriptRouter) Process(event 
*config_center.ConfigChangeEvent) {
 
        rawConf, ok := event.Value.(string)
        if !ok {
-               panic(ok)
+               logger.Errorf("[Router][Script] route config value must be 
string, actualType=%T", event.Value)
+               return

Review Comment:
   `Process` now type-asserts `event.Value` to `string` before checking 
`event.ConfigType`. For `EventTypeDel`, config-center payloads may be 
`nil`/non-string (and delete events don't need a body), so this returns early 
and never clears/destroys the existing rule, leaving stale router state.



##########
cluster/router/script/router_test.go:
##########
@@ -227,6 +227,17 @@ script: |
        }
 }
 
+func TestScriptRouterProcessSkipsNonStringConfig(t *testing.T) {
+       s := &ScriptRouter{}
+
+       assert.NotPanics(t, func() {
+               s.Process(&config_center.ConfigChangeEvent{Key: "", Value: 123, 
ConfigType: remoting.EventTypeUpdate})
+       })
+       assert.False(t, s.enabled)
+       assert.Empty(t, s.scriptType)
+       assert.Empty(t, s.rawScript)
+}
+

Review Comment:
   The regression test only verifies the zero-value router stays disabled; it 
doesn't verify that an invalid (non-string) update leaves an existing 
enabled/configured router unchanged. Since `Process` returns early, state 
should remain exactly as-is; adding a non-zero initial state makes the test 
catch accidental mutations.



-- 
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]

Reply via email to