Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recover panics #1009

Merged
merged 2 commits into from
Dec 2, 2019
Merged

recover panics #1009

merged 2 commits into from
Dec 2, 2019

Conversation

vtolstov
Copy link
Contributor

@vtolstov vtolstov commented Dec 2, 2019

No description provided.

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
server/rpc_router.go Outdated Show resolved Hide resolved
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
@asim asim merged commit b5d6530 into micro:master Dec 2, 2019
@vtolstov vtolstov deleted the panics branch December 2, 2019 23:31
@@ -505,6 +507,17 @@ func (router *router) Subscribe(s Subscriber) error {
}

func (router *router) ProcessMessage(ctx context.Context, msg Message) error {
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should define in named return value. it will doesn't work when defer recover.

func (router *router) ProcessMessage(ctx context.Context, msg Message) (err error) {

@@ -16,6 +17,8 @@ type microTransport struct {
}

func (m *microTransport) Stream(ts pb.Transport_StreamServer) error {
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

        fn := func() error {
            var err error
            defer func() {
                if r := recover(); r != nil {
                    err = fmt.Errorf("%v", r)
                }   
            }() 
            panic("micro")
            return err
        }   

        fmt.Println(fn()) // print nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants