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

How to create a custom recover? #2004

Closed
trietphm opened this issue Jun 21, 2016 · 4 comments
Closed

How to create a custom recover? #2004

trietphm opened this issue Jun 21, 2016 · 4 comments
Milestone

Comments

@trietphm
Copy link

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go and beego are you using (bee version)?
    bee :1.4.1
    beego :1.6.1
    Go :go version go1.6.2 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    GOARCH="amd64"
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
  3. What did you do?
    Create an admin website

How to override Beego's recoverPanic? I have set recoverpanic = false and write my own recover but have no luck

func main() {
    defer recoverPanic()
    beego.Run()
}

func recoverPanic() {
    if err := recover(); err != nil {
        fmt.Println("Panic should go there")
    }
}
@astaxie
Copy link
Member

astaxie commented Jun 24, 2016

Beego's recoverPanic has a lot logic inside. why you want to overwrite it? what do you want to solve? Do you want to define the error page? If that the case please reference to http://beego.me/docs/mvc/controller/errors.md

@trietphm
Copy link
Author

Hi @astaxie
I want to catch all unexpected error, e.g. nil pointer. And do some stuff such as send email to our maintainers.

@trietphm
Copy link
Author

Example, an unexpected nil pointer error

    var t *Campaign
    log.Println(t.ID)
    log.Println("Can you go there?")

In console, it showed

2016/06/24 11:53:03 [router.go:854][C] the request url is  /campaign 
2016/06/24 11:53:03 [router.go:855][C] Handler crashed with error runtime error: invalid memory address or nil pointer dereference 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/asm_amd64.s:472 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/panic.go:426 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/panic.go:45 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/sigpanic_unix.go:24 
2016/06/24 11:53:03 [router.go:861][C] /home/windyzboy/go/src/waudio-server/admin/controllers/campaign_controller.go:25 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/asm_amd64.s:472 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/reflect/value.go:435 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/reflect/value.go:303 
2016/06/24 11:53:03 [router.go:861][C] /home/windyzboy/go/src/github.com/astaxie/beego/router.go:778 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/net/http/server.go:2081 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/net/http/server.go:1472 
2016/06/24 11:53:03 [router.go:861][C] /usr/local/go/src/runtime/asm_amd64.s:1998 

I want to custom this page and send email to our maintainers.

image

@astaxie
Copy link
Member

astaxie commented Jun 24, 2016

We didn't support that now. But that's a good example to support a recover hook

@astaxie astaxie added this to the beego1.7.1 milestone Aug 17, 2016
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

No branches or pull requests

2 participants