metaverse / truss

Truss helps you build go-kit microservices without having to worry about writing or maintaining boilerplate code.
Other
737 stars 144 forks source link

WARN[0000] Code formatting error, generated service will not build, outputting unformatted code #340

Closed douchunrong closed 3 years ago

douchunrong commented 3 years ago

my proto file:

dssp_engine_execute.proto

syntax = "proto3";
package dssp_engine_execute;

import "github.com/metaverse/truss/deftree/googlethirdparty/annotations.proto";
import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";

service DsspEngineExecute {
  rpc Deploy (DeployRequest) returns (DefaultResponse) {
    option (google.api.http) = {
      custom {
        kind: "HEAD"
        path: "/dssp_engine_execute/workflow/deploy"
      }
      additional_bindings {
        post: "/dssp_engine_execute/workflow/deploy"
        body : "*"
      }
    };
  }
}

message DeployRequest {
  google.protobuf.Any metadata = 1;
}

message DefaultResponse {
  ResponseMap resp = 1;
}

message ResponseMap {
  string message = 1;
  int32 code = 2;
  google.protobuf.Struct data = 3;
}

when i run truss dssp_engine_execute.proto return WARN:

WARN[0000] Code formatting error, generated service will not build, outputting unformatted code  error="532:1: expected statement, found '%'"

and in transport_http.go file `:

if MetadataTraceStrArr, ok := queryParams["metadata"]; ok {
MetadataTraceStr := MetadataTraceStrArr[0]
%!(EXTRA string=MetadataTrace, string=MetadataTraceStr)
if err != nil {
    return nil, errors.Wrap(err, fmt.Sprintf("Error while extracting MetadataTrace from query, queryParams: %v", queryParams))
}
req.Metadata = MetadataTrace
}

how can i fix it ? anyone help me?

zaquestion commented 3 years ago

Hi @douchunrong I think I see the issue, looks like we could use some better handling somewhere to warn about this. But truss is trying to generate queryParam logic for your DeployRequest message. This is because the HEAD request blob you have doesn't indicate to put the fields in the body, so it defaults to in the query params.

There are 2 possible ways to fix this, one that might work, and one that I'm sure will work.

The one that might work, is to simply add body : "*" to the head request blob, that should allow the code to pass generation (as it will no longer attempt to generate query params) and I believe operate as you expect.

The other approach which I use in my own services for OPTIONS requests is to define a separate rps for the HEAD request. Something like:

message Empty {}

// With the following additional RPC defined in your service
  rpc DeployHEAD (Empty) returns (Empty) {
    option (google.api.http) = {
      custom {
        kind: "HEAD"
        path: "/dssp_engine_execute/workflow/deploy"
      }
    };

Hope this helps!

douchunrong commented 3 years ago

Hi @douchunrong I think I see the issue, looks like we could use some better handling somewhere to warn about this. But truss is trying to generate queryParam logic for your DeployRequest message. This is because the HEAD request blob you have doesn't indicate to put the fields in the body, so it defaults to in the query params.

There are 2 possible ways to fix this, one that might work, and one that I'm sure will work.

The one that might work, is to simply add body : "*" to the head request blob, that should allow the code to pass generation (as it will no longer attempt to generate query params) and I believe operate as you expect.

The other approach which I use in my own services for OPTIONS requests is to define a separate rps for the HEAD request. Something like:

message Empty {}

// With the following additional RPC defined in your service
  rpc DeployHEAD (Empty) returns (Empty) {
    option (google.api.http) = {
      custom {
        kind: "HEAD"
        path: "/dssp_engine_execute/workflow/deploy"
      }
    };

Hope this helps!

yes, thank's for your help. it's worked for me.