Skip to content

Commit

Permalink
Fixed CheckIfAnyError() on RPCTimeout. (#974)
Browse files Browse the repository at this point in the history
* Added errorIndexInReturnedValues as a parameter in  function

* Fixed comparios of error data type from returned values
  • Loading branch information
Yashk767 authored Oct 12, 2022
1 parent b55240a commit 7e44818
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions utils/struct-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,20 @@ func InvokeFunctionWithTimeout(interfaceName interface{}, methodName string, arg
}

func CheckIfAnyError(result []reflect.Value) error {
rpcError := errors.New("RPC Timeout error")
if result == nil {
return rpcError
return errors.New("RPC timeout error")
}

errorDataType := reflect.TypeOf((*error)(nil)).Elem()
errorIndexInReturnedValues := -1

for i := range result {
returnedValue := result[i]
if reflect.TypeOf(returnedValue.Interface()) == reflect.TypeOf(rpcError) {
errorIndexInReturnedValues = i
returnedValueDataType := reflect.TypeOf(returnedValue.Interface())
if returnedValueDataType != nil {
if returnedValueDataType.Implements(errorDataType) {
errorIndexInReturnedValues = i
}
}
}
if errorIndexInReturnedValues == -1 {
Expand Down

0 comments on commit 7e44818

Please sign in to comment.