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

invalid memory address or nil pointer dereference when registering centralized error handler #261

Closed
arpodungge opened this issue Jul 30, 2019 · 2 comments
Assignees
Labels

Comments

@arpodungge
Copy link

arpodungge commented Jul 30, 2019

Using aah v0.12.3

I'm creating a new api project with aah new
I've found an issue when i try to create centralized error handler by creating AppErrorHandler function and register it in init.go by following the instruction from
https://docs.aahframework.org/v0.12/error-handling.html#registering-centralized-error-handler

func AppErrorHandler(ctx *aah.Context, err *aah.Error) bool {
    switch err.Code {
	case 400:
		// handle bad request
	case 401:
		// handle unauthenticated request
	case 403:
		// handle permission issues
	case 500:
		// handle internal server issues
    }
    return true
}
func init() {
    app := aah.App()
    app.SetErrorHandler(AppErrorHandler)
}

an error occurred when i run it with aah run :

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8a7974]

goroutine 1 [running]:
aahframe%2ework.(*errorManager).SetHandler(0x0, 0xa29780)
/home/user1/go/pkg/mod/aahframe.work@v0.12.3/error.go:132 +0x34
aahframe%2ework.(*Application).SetErrorHandler(0xc0001e21c0, 0xa29780)
/home/user1/go/pkg/mod/aahframe.work@v0.12.3/aah.go:400 +0x3c
main.init.0()
/home/user1/ws_aah/aah-app/app/init.go:43 +0x118
FATAL aah application did not start

Thanks

@jeevatkm jeevatkm self-assigned this Jul 31, 2019
@jeevatkm
Copy link
Member

@arpodungge It seems I need to update the documentation. Please use OnStart event, update your code to

app := aah.App()
app.OnStart(func(e *aah.Event) {
  app.SetErrorHandler(AppErrorHandler)
})

@jeevatkm
Copy link
Member

I'm closing this one. Please let me know.

RB-Lab added a commit to RB-Lab/docs that referenced this issue Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants