Skip to content

Commit

Permalink
fix(server): don't attempt to unmarshal empty params (#10)
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
andrewmbenton authored Dec 11, 2024
1 parent c4e4ab9 commit f79c24e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Request struct {
ID json.Number `json:"id"`
JsonRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
Params json.RawMessage `json:"params,omitempty"`
}

type Response struct {
Expand Down
6 changes: 4 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ func process[T, V any](ctx context.Context, cfg *serverConfig, msg jsonrpc.Reque
)
}

if err := json.Unmarshal(msg.Params, &params); err != nil {
return nil, err
if len(msg.Params) > 0 {
if err := json.Unmarshal(msg.Params, &params); err != nil {
return nil, err
}
}
req := NewRequest(params)
req.id = msg.ID.String()
Expand Down

0 comments on commit f79c24e

Please sign in to comment.