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


##########
filter/generic/service_filter_test.go:
##########
@@ -269,6 +269,55 @@ func TestServiceFilter_InvokeWithUnsupportedGenericMode(t 
*testing.T) {
        }
 }
 
+// TestServiceFilter_InvokeRejectsMalformedArgs ensures a $invoke with 
wrong-typed
+// arguments returns an error instead of panicking. See 
service_filter.go:79,82.

Review Comment:
   The test comment references specific line numbers in `service_filter.go` 
(`79,82`), which will drift over time. Prefer referencing the behavior (e.g., 
“guards arg[0]/arg[2] type assertions”) or linking to an issue/PR instead of 
line numbers.



##########
filter/generic/service_filter.go:
##########
@@ -76,10 +76,16 @@ func (f *genericServiceFilter) Invoke(ctx context.Context, 
invoker base.Invoker,
        }
 
        // get real invocation info from the generic invocation
-       mtdName := inv.Arguments()[0].(string)
+       mtdName, ok := inv.Arguments()[0].(string)
+       if !ok {
+               return &result.RPCResult{Err: perrors.Errorf("$invoke: arg[0] 
must be string, got %T", inv.Arguments()[0])}
+       }
        // types are not required in dubbo-go, for dubbo-go client to dubbo-go 
server, types could be nil
        types := inv.Arguments()[1]
-       args := inv.Arguments()[2].([]hessian.Object)
+       args, ok := inv.Arguments()[2].([]hessian.Object)
+       if !ok {
+               return &result.RPCResult{Err: perrors.Errorf("$invoke: arg[2] 
must be []hessian.Object, got %T", inv.Arguments()[2])}
+       }

Review Comment:
   `inv.Arguments()` is called multiple times and indexed repeatedly. Storing 
the slice once (e.g., `arguments := inv.Arguments()`) makes the code clearer, 
avoids repeating indexing logic, and guarantees the same snapshot is used for 
both the assertion and the error message.



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