Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
172f7778
Unverified
Commit
172f7778
authored
Feb 11, 2020
by
Adam Schmideg
Committed by
GitHub
Feb 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: add error when call result parameter is not addressable (#20638)
parent
34bb132b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
client.go
rpc/client.go
+3
-0
client_test.go
rpc/client_test.go
+17
-0
No files found.
rpc/client.go
View file @
172f7778
...
...
@@ -276,6 +276,9 @@ func (c *Client) Call(result interface{}, method string, args ...interface{}) er
// The result must be a pointer so that package json can unmarshal into it. You
// can also pass nil, in which case the result is ignored.
func
(
c
*
Client
)
CallContext
(
ctx
context
.
Context
,
result
interface
{},
method
string
,
args
...
interface
{})
error
{
if
result
!=
nil
&&
reflect
.
TypeOf
(
result
)
.
Kind
()
!=
reflect
.
Ptr
{
return
fmt
.
Errorf
(
"call result parameter must be pointer or nil interface: %v"
,
result
)
}
msg
,
err
:=
c
.
newMessage
(
method
,
args
...
)
if
err
!=
nil
{
return
err
...
...
rpc/client_test.go
View file @
172f7778
...
...
@@ -49,6 +49,23 @@ func TestClientRequest(t *testing.T) {
}
}
func
TestClientResponseType
(
t
*
testing
.
T
)
{
server
:=
newTestServer
()
defer
server
.
Stop
()
client
:=
DialInProc
(
server
)
defer
client
.
Close
()
if
err
:=
client
.
Call
(
nil
,
"test_echo"
,
"hello"
,
10
,
&
echoArgs
{
"world"
});
err
!=
nil
{
t
.
Errorf
(
"Passing nil as result should be fine, but got an error: %v"
,
err
)
}
var
resultVar
echoResult
// Note: passing the var, not a ref
err
:=
client
.
Call
(
resultVar
,
"test_echo"
,
"hello"
,
10
,
&
echoArgs
{
"world"
})
if
err
==
nil
{
t
.
Error
(
"Passing a var as result should be an error"
)
}
}
func
TestClientBatchRequest
(
t
*
testing
.
T
)
{
server
:=
newTestServer
()
defer
server
.
Stop
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment