Skip to content
New issue

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

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

Already on GitHub? # to your account

Missing #[derive(Debug)] in generated code #298

Closed
nikclayton-dfinity opened this issue Mar 20, 2020 · 2 comments · Fixed by #312
Closed

Missing #[derive(Debug)] in generated code #298

nikclayton-dfinity opened this issue Mar 20, 2020 · 2 comments · Fixed by #312
Assignees
Milestone

Comments

@nikclayton-dfinity
Copy link

Bug Report

Version

0.1.1 (both tonic and tonic-build)

Platform

Darwin Niks-MBP 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin

Description

I'm experimenting with a server that maintains connections to multiple peers, with peers coming and going. My client type is GossipClient.

I'm trying to store the peer clients in a variable of type Arc<Vec<GossipClient<tonic::transport::Channel>>>

When I do this I get the following error at build time:

error[E0277]: `gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>` doesn't implement `std::fmt::Debug`
  --> src/client-server.rs:22:5
   |
22 |     peer_clients: Arc<Vec<GossipClient<tonic::transport::Channel>>>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>` cannot be formatted using `{:?}`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>`
   = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
   = note: required because of the requirements on the impl of `std::fmt::Debug` for `std::vec::Vec<gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>>`
   = note: required because of the requirements on the impl of `std::fmt::Debug` for `std::sync::Arc<std::vec::Vec<gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>>>`
   = note: required because of the requirements on the impl of `std::fmt::Debug` for `&std::sync::Arc<std::vec::Vec<gossip_wire::gossip_client::GossipClient<tonic::transport::channel::Channel>>>`
   = note: required for the cast to the object type `dyn std::fmt::Debug`

error: aborting due to previous error

If I hand-edit the generated gossip.rs file (generated from the .proto file), find the generated

    pub struct GossipClient<T> {
        inner: tonic::client::Grpc<T>,
    }

and add a #[derive(Debug)] immediately before it it works.

@nikclayton-dfinity
Copy link
Author

nikclayton-dfinity commented Mar 20, 2020

diff --git a/tonic-build/src/client.rs b/tonic-build/src/client.rs
index 39b8c04..f66d075 100644
--- a/tonic-build/src/client.rs
+++ b/tonic-build/src/client.rs
@@ -19,6 +19,7 @@ pub fn generate<'a, T: Service<'a>>(service: &'a T, context: &T::Context) -> Tok
             use tonic::codegen::*;

             #service_doc
+            #[derive(Debug)]
             pub struct #service_ident<T> {
                 inner: tonic::client::Grpc<T>,
             }

fixes.

@LucioFranco
Copy link
Member

@nikclayton-dfinity this sounds like a great idea! Would totally accept a PR :) We prob want to add this to all external facing structs that codegen produces.

@jen20 jen20 self-assigned this Mar 26, 2020
@LucioFranco LucioFranco added this to the 0.2 milestone Mar 27, 2020
jen20 added a commit that referenced this issue Mar 30, 2020
jen20 added a commit that referenced this issue Mar 30, 2020
jen20 added a commit that referenced this issue Mar 30, 2020
jen20 added a commit that referenced this issue Mar 30, 2020
jen20 added a commit that referenced this issue Mar 30, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants