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

panic: runtime error: invalid memory address or nil pointer dereference #2

Open
liuzehao opened this issue Mar 9, 2021 · 1 comment

Comments

@liuzehao
Copy link

liuzehao commented Mar 9, 2021

I follow your tutorial completely, but in the [gRPC #10.1] Implement unary gRPC API - Golang,I encountered the following error:

Running tool: /usr/local/opt/go/libexec/bin/go test -timeout 30s -run ^TestServerCreateLaptop$ gitlab.com/techschool/pcbook/service

--- FAIL: TestServerCreateLaptop (0.00s)
--- FAIL: TestServerCreateLaptop/success_with_id (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x14bfe44]

goroutine 35 [running]:
testing.tRunner.func1.1(0x15663a0, 0x1a9bd50)
/usr/local/opt/go/libexec/src/testing/testing.go:940 +0x2f5
testing.tRunner.func1(0xc0000ba000)
/usr/local/opt/go/libexec/src/testing/testing.go:943 +0x3f9
panic(0x15663a0, 0x1a9bd50)
/usr/local/opt/go/libexec/src/runtime/panic.go:969 +0x166
gitlab.com/techschool/pcbook/service.(*LaptopServer).CreateLaptop(0xc000094f30, 0x16d9a20, 0xc00011e008, 0xc000094f40, 0x160134df, 0xc000046800, 0xc000094f18)
/Users/mac/Documents/golang/pcbook/service/laptop_server.go:47 +0x124
gitlab.com/techschool/pcbook/service_test.TestServerCreateLaptop.func1(0xc0000ba000)
/Users/mac/Documents/golang/pcbook/service/laptop_server_test.go:72 +0xd0
testing.tRunner(0xc0000ba000, 0xc0000a4ac0)
/usr/local/opt/go/libexec/src/testing/testing.go:991 +0xdc
created by testing.(*T).Run
/usr/local/opt/go/libexec/src/testing/testing.go:1042 +0x357
FAIL gitlab.com/techschool/pcbook/service 0.892s
FAIL
I don't know how to solve it. Can you help me?

@yuvan11
Copy link

yuvan11 commented Jul 9, 2021

@liuzehao I also encountered the same issue while following [gRPC #10.1] Implement unary gRPC API - Golang,

I solved it by replacing few lines of code,

pb

changing to

image

Reference files,
laptop_server.go : https://gist.github.com/yuvan11/ab0f4aea31149f0617847c84796c5e96
laptop_server_test.go : https://gist.github.com/yuvan11/5881101dd93810983f9ac1243f8cbd89

After doing that, test file got passed.

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