infobloxopen / protoc-gen-gorm

A protobuf compiler plugin designed to generate GORM models and APIs for simple object persistence tasks.
Apache License 2.0
557 stars 162 forks source link

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

Open an15221315127 opened 2 years ago

an15221315127 commented 2 years ago

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

goroutine 1 [running]: github.com/infobloxopen/protoc-gen-gorm/plugin.(ORMBuilder).followsUpdateConventions(0xc0000671a0, 0xc000828ea0, 0xc000828ea0, {0x13bb7c7, 0x6}) /Users/anguodong/go/pkg/mod/github.com/infobloxopen/protoc-gen-gorm@v1.1.0/plugin/plugin.go:2814 +0x20e github.com/infobloxopen/protoc-gen-gorm/plugin.(ORMBuilder).parseServices(0xc0000671a0, 0xc0001be100) /Users/anguodong/go/pkg/mod/github.com/infobloxopen/protoc-gen-gorm@v1.1.0/plugin/plugin.go:2641 +0x54e github.com/infobloxopen/protoc-gen-gorm/plugin.(*ORMBuilder).Generate(0xc0000671a0) /Users/anguodong/go/pkg/mod/github.com/infobloxopen/protoc-gen-gorm@v1.1.0/plugin/plugin.go:282 +0x251 main.main() /Users/anguodong/go/pkg/mod/github.com/infobloxopen/protoc-gen-gorm@v1.1.0/main.go:33 +0xb0 --gorm_out: protoc-gen-gorm: Plugin failed with status code 2. make: *** [api] Error 1

nonaxanon commented 2 years ago

get this issue too for whenever I have an Update prefix and a string id = 1 and other types on the Request

AFMiziara commented 2 years ago

Same here

nonaxanon commented 2 years ago

I solved this issue by modifying plugin.go, in line 2811 added several nil checks Also I upgraded to a new buf builder, 1.4.0 if field == nil || field.Desc == nil || field.Desc.Message() == nil { return false, "", "" } if field.Desc.Message().FullName() == "" { return false, "", "" }

AFMiziara commented 2 years ago

Thanks for sharing @nonaxanon ! Any chances these changes can be introduced in here?

saltbo commented 2 years ago

I solved this issue by modifying plugin.go, in line 2811 added several nil checks Also I upgraded to a new buf builder, 1.4.0 if field == nil || field.Desc == nil || field.Desc.Message() == nil { return false, "", "" } if field.Desc.Message().FullName() == "" { return false, "", "" }

This is not a good resolution.

Doc: Request messages for Create and Update methods should have an Ormable Type in a field named payload

If not the basic Update, should not name UpdateXXX

gsingh-ds commented 1 year ago

why it requires you to add payload field to update when autogen is not specified?

C0rWin commented 9 months ago

Is this is for Update prefixed APIs? I have create a project (https://github.com/C0rWin/buf-gorm-demo/blob/main/protos/entity.proto) to demonstrate the behavour which leads to the panic and to be honest I am not clear what is the root cause leading to the panic.

PS. Noted that most comments are almost one year old while still facing this issue, hence wondering whenever it was addressed? Or this is an expected and I'm just doing something wrong?

floating-yuan commented 7 months ago

still facing this issue...

sansan36 commented 7 months ago

I solved this by change every messages named "Update". for me, I change to "Edit", and everything ok