Skip to content

Commit

Permalink
Handle deserialize panic
Browse files Browse the repository at this point in the history
  • Loading branch information
gboddin committed Aug 24, 2023
1 parent 3199bf7 commit ced7962
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage.txt
coverage.txt
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Golang Hessian
# Golang Hessian

[![Build Status](https://travis-ci.org/ggwhite/go-hessian.svg?branch=master)](https://travis-ci.org/ggwhite/go-hessian)
[![codecov](https://codecov.io/gh/ggwhite/go-hessian/branch/master/graph/badge.svg)](https://codecov.io/gh/ggwhite/go-hessian)
Expand Down Expand Up @@ -152,4 +152,4 @@ Result:
|list |Y |Y |V type? length? object* z |
|map |Y |Y |M t b16 b8 type-string (object, object)* z |
|ref |N |N | |
|remote |N |N | |
|remote |N |N | |
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/LeakIX/go-hessian

go 1.20
11 changes: 8 additions & 3 deletions proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hessian

import (
"errors"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -49,7 +50,7 @@ type Proxy struct {
}

// Invoke input method name and arguments, it will send request to server, and parse response to interface
func (c *Proxy) Invoke(m string, args ...interface{}) ([]interface{}, error) {
func (c *Proxy) Invoke(m string, args ...interface{}) (_ []interface{}, err error) {

c.serializer.Flush()

Expand All @@ -76,12 +77,16 @@ func (c *Proxy) Invoke(m string, args ...interface{}) ([]interface{}, error) {
}

c.deserializer.Reset(resp.Body)

// Set the default error return value
err = errors.New("deserialize failed")
defer func() {
// Recover on read issues
_ = recover()
}()
ans, err := c.deserializer.Read()
if err != nil {
return nil, err
}

return ans, nil
}

Expand Down
2 changes: 1 addition & 1 deletion test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"time"

hessian "github.com/ggwhite/go-hessian"
hessian "github.com/LeakIX/go-hessian"
)

type User struct {
Expand Down

0 comments on commit ced7962

Please sign in to comment.