Loading

Kitex+protobuf 生成报错mismatched input 'required' expecting

前言

今天接到个需求,需要接入中台那边的支付功能,然后中台那边是以微服务的方式去部署了支付服务,需要业务侧使用kitex+proto生成对应的client进行对应的协议接口生成

本地环境

OS: Mac-M1
Go:1.22.7
Kitex: 0.13.1
Protoc: libprotoc 29.3

错误表现

[INFO ] idl/paymentrpc.proto: parsing
[ERROR] syntax error at line 966 column 8 - mismatched input 'required' expecting {'syntax', 'edition', 'import', 'weak', 'public', 'package', 'option', 'optional', 'repeated', 'oneof', 'map', 'int32', 'int64', 'uint32', 'uint64', 'sint32', 'sint64', 'fixed32', 'fixed64', 'sfixed32', 'sfixed64', 'bool', 'string', 'double', 'float', 'bytes', 'reserved', 'extensions', 'to', 'max', 'enum', 'message', 'service', 'extend', 'rpc', 'stream', 'returns', BOOL_LIT, IDENTIFIER}
[FATAL] idl/paymentrpc.proto: error occurred during parsing proto file

在中台提供的proto文件中有个字段叫做required,然后required在proto2中是关键字,但是在proto3中移除了。

错误排查

  • 因为同事的OS与Go版本跟我是一致的,但是他却可以编译通过,所以排除了Go与OS的影响

  • 后面我把本地protoc降级为跟他一致版本仍然不能通过

  • 然后尝试把kitex降级,后成功通过

总结

看上去是kitex,字节他本身的原因,为此我还特地去找字节的朋友吐槽这件事情,结果是他们内部也有着问题,让我换包换Go版本😅

posted @ 2025-06-09 14:16  ViKyanite  阅读(41)  评论(2)    收藏  举报