yoheimuta / go-protoparser

Yet another Go package which parses a Protocol Buffer file (proto2+proto3)
MIT License
166 stars 20 forks source link

Wrap errors from invalid bodies to be more descriptive #54

Closed mattheath closed 3 years ago

mattheath commented 3 years ago

I had some difficulty locating a bug in a .proto file which was caused parsing to fail, but where our other tools (using protoc) were successfully generating the Go protobuf files, as the error message wasn't clear to me (as an infrequent user).

I was receiving this error message:

invalid MessageBody type &{<nil>} of &{<nil>}

But it was unclear to me which Message (in a fairly long proto file) was the source of this. Inevitably it was due to a typo with an extra semicolon at the end of one of the field definitions:

repeated string fields = 3 ;;

Could we perhaps wrap the error when interpreting Enums, Messages, and Services, with their name so it's easier to find the source of the error? This uses the error wrapping introduced in Go 1.13, so that the original error can still be retrieved via Unwrap() and examined with Is and As. Very happy to change this if there's a preferred alternative!

yoheimuta commented 3 years ago

ref. https://github.com/yoheimuta/go-protoparser/releases/tag/v4.2.1

mattheath commented 3 years ago

Thanks! 💖