Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error will occur if you name your protobuf service "Result" #1156

Closed
stevenhansel opened this issue Nov 19, 2022 · 3 comments · Fixed by #1337
Closed

An error will occur if you name your protobuf service "Result" #1156

stevenhansel opened this issue Nov 19, 2022 · 3 comments · Fixed by #1337

Comments

@stevenhansel
Copy link

Bug Report

Version

tonic 0.8
tonic-build 0.8

Platform

Darwin june.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:35 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T8101 arm64

Description

I found out an unique bug, I happened to name my proto service as "Result" because it's supposed to stream the result of a service. Here is my proto definition:

result.proto

syntax = "proto3";

import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";

option go_package = "github.com/stevenhansel/binus-logbook/scraper/internal/grpc/proto/result";

package result;

service Result {
  rpc Listen(google.protobuf.Empty) returns (stream Reply) {}
}

message Reply {
  int32 step = 1;
  string name = 2;
  google.protobuf.Any data = 3;
}

Then when I run cargo build where inside in the build.rs looks like:

build.rs

fn main() {
    let protos: &'static [&str] = &[
        "../proto/helloworld.proto",
        "../proto/scraper.proto",
        "../proto/result.proto",
    ];

    for proto in protos {
        tonic_build::compile_protos(proto)
            .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e));
    }
    tauri_build::build()
}

It will show this error:

error[E0782]: trait objects must include the `dyn` keyword
   --> /Users/june/binus-logbook/src-tauri/target/debug/build/binus-logbook-69ad9dfa394bbbc0/out/result.rs:110:24
    |
110 |                 Item = Result<super::Reply, tonic::Status>,
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
help: add `dyn` keyword before this trait
    |
110 -                 Item = Result<super::Reply, tonic::Status>,
110 +                 Item = dyn Result<super::Reply, tonic::Status>,
    |

error[E0107]: this trait takes 0 generic arguments but 2 generic arguments were supplied
   --> /Users/june/binus-logbook/src-tauri/target/debug/build/binus-logbook-69ad9dfa394bbbc0/out/result.rs:110:24
    |
110 |                 Item = Result<super::Reply, tonic::Status>,
    |                        ^^^^^^----------------------------- help: remove these generics
    |                        |
    |                        expected 0 generic arguments
    |
note: trait defined here, with 0 generic parameters
   --> /Users/june/binus-logbook/src-tauri/target/debug/build/binus-logbook-69ad9dfa394bbbc0/out/result.rs:107:15
    |
107 |     pub trait Result: Send + Sync + 'static {
    |               ^^^^^^

error[E0191]: the value of the associated type `ListenStream` (from trait `result_server::Result`) must be specified
   --> /Users/june/binus-logbook/src-tauri/target/debug/build/binus-logbook-69ad9dfa394bbbc0/out/result.rs:110:24
    |
109 | /         type ListenStream: futures_core::Stream<
110 | |                 Item = Result<super::Reply, tonic::Status>,
    | |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: specify the associ

For me the fix was to rename the protobuf service in result.proto to another name.

result.proto

syntax = "proto3";

import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";

option go_package = "github.com/stevenhansel/binus-logbook/scraper/internal/grpc/proto/result";

package result;

service ResultListener {
  rpc Listen(google.protobuf.Empty) returns (stream Reply) {}
}

message Reply {
  int32 step = 1;
  string name = 2;
  google.protobuf.Any data = 3;
}

I'm reporting this bug because it works just fine when I compile the protobuf with protoc for the Golang side.

@LucioFranco
Copy link
Member

Yeah, i think this is something that is hard to fix due to Result being imported in the prelude. I would consider changing the name as it may just be incompatible with Rust.

@davidpdrsn
Copy link
Member

I think if the generated code used a fully qualified path like ::std::result::Result then it should work.

@stevenhansel
Copy link
Author

I think if the generated code used a fully qualified path like ::std::result::Result then it should work.

Great idea, I think I can open up a PR in the weekend if we're going with this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants