starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.73k stars 387 forks source link

error: field name expected #191

Closed elvizlai closed 2 years ago

elvizlai commented 2 years ago

error detail

2022/04/13 05:20:22 [error] 183#183: *85 lua entry thread aborted: runtime error: /etc/nginx/lualib/protoc.lua:229: /etc/proto/hello.proto:1:8: field name expected
stack traceback:
coroutine 0:
    [C]: in function 'full_ident'
    /etc/nginx/lualib/protoc.lua:229: in function 'structure'
    /etc/nginx/lualib/protoc.lua:261: in function 'constant'
    /etc/nginx/lualib/protoc.lua:695: in function 'option'
    /etc/nginx/lualib/protoc.lua:741: in function 'body_parser'
    /etc/nginx/lualib/protoc.lua:767: in function 'top_parser'
    /etc/nginx/lualib/protoc.lua:852: in function 'parse'
    /etc/nginx/lualib/protoc.lua:330: in function 'f'
    /etc/nginx/lualib/protoc.lua:1158: in function 'do_compile'
    /etc/nginx/lualib/protoc.lua:1174: in function 'compilefile'
    /etc/nginx/lualib/protoc.lua:1187: in function 'loadfile'
    content_by_lua(gw.conf:85):17: in main chunk, client: 172.17.0.1, server: , request: "POST /test HTTP/1.1", host: "localhost:8080"

The imported file was placed at same folder /etc/proto/

hello.proto

syntax = "proto3";

package pb;

option go_package = "examples/pb";

import "google/api/annotations.proto";

enum E {
  E_UNSPECIFIED = 0;
  E_1           = 1;
  E_2           = 2;
}

message Empty {
}

message Payload {
  string          field_1 = 1;
  int32           field_2 = 2;
  E               filed_3 = 3;
  repeated string field_4 = 4;
  map<string, E>  filed_5 = 5;
  oneof           x {
    bool   f1 = 6;
    string f2 = 7;
  }
}

service HelloService {
  rpc Ping(Empty) returns (Payload) {
    option (google.api.http) = {
      post: "/ping"
      body: "*"
    };
  };
};

nginx gw.conf

server {
    listen 8080;

    location /test {
        content_by_lua_block {
            local protoc = require "protoc"
            local pl_path = require "pl.path"

            fname="/etc/proto/hello.proto"
            local dir = pl_path.splitpath(pl_path.abspath(fname))
            local p = protoc.new()
            p:addpath("/usr/include")
            p:addpath("/usr/local/opt/protobuf/include/")
            p:addpath("spec/fixtures/grpc")

            p.include_imports = true
            p:addpath(dir)
            p:loadfile(fname)
            local parsed = p:parsefile(fname)
        }
    }
}
starwing commented 2 years ago

It seems works on the latest Lua-protobuf version (HEAD of this repo).

elvizlai commented 2 years ago

It seems works on the latest Lua-protobuf version (HEAD of this repo).

Yes, I tried HEAD, it works, but 0.3.4 does not.

starwing commented 2 years ago

Yes, it fixed at https://github.com/starwing/lua-protobuf/commit/477581fb2ef50dfe3988896f03cd93ac0b8aef50