Skip to content

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

@liuzehao

Description

@liuzehao

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions