question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error using package namespace in proto with . in it

See original GitHub issue

I have found an issue where grpc-dynamic-gateway crashes if the package in the proto file contains a . in it (which is helpful for clean code generation in languages like C++)

i.e. this fails:

syntax = "proto3";

package test.stuff;

import "google/api/annotations.proto";

service TestService
{
	rpc TestRpc (TestParams) returns (TestData)
	{
		option (google.api.http) =
		{
			post: "/v1/assets/op/execute"
			body: "*"
		};
	}
}

message TestParams
{
	string testField = 1;
}

message TestData
{
	string myData = 1;
}

With this error:

C:\Users\graham\Documents\Repositories\halcyon>grpc-dynamic-gateway -g 0.0.0.0:50060 -I ./Proto/proto AssetService2.proto
C:\Users\graham\AppData\Roaming\npm\node_modules\grpc-dynamic-gateway\index.js:34
        clients[pkg][svc] = new protos[si][pkg][svc](grpcLocation, credentials)
                                               ^

TypeError: Cannot read property 'TestService' of undefined
    at sch.services.forEach.s (C:\Users\graham\AppData\Roaming\npm\node_modules\grpc-dynamic-gateway\index.js:34:48)
    at Array.forEach (native)
    at protoFiles.map.map.forEach (C:\Users\graham\AppData\Roaming\npm\node_modules\grpc-dynamic-gateway\index.js:32:20)
    at Array.forEach (native)
    at middleware (C:\Users\graham\AppData\Roaming\npm\node_modules\grpc-dynamic-gateway\index.js:29:6)
    at Object.<anonymous> (C:\Users\graham\AppData\Roaming\npm\node_modules\grpc-dynamic-gateway\cli.js:61:26)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

While this:

syntax = "proto3";

package teststuff;

import "google/api/annotations.proto";

service TestService
{
	rpc TestRpc (TestParams) returns (TestData)
	{
		option (google.api.http) =
		{
			post: "/v1/assets/op/execute"
			body: "*"
		};
	}
}

message TestParams
{
	string testField = 1;
}

message TestData
{
	string myData = 1;
}

Works fine:

C:\Users\graham\Documents\Repositories\halcyon>grpc-dynamic-gateway -g 0.0.0.0:50060 -I ./Proto/proto AssetService2.proto
POST /v1/assets/op/execute
Listening on http://0.0.0.0:8080, proxying to gRPC on 0.0.0.0:50060

Thank you, Graham

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xsorifc28commented, Apr 24, 2018

Changing the getPkg function to this should fix it:

const getPkg = (client, pkg, create = false) => {
  if (!((pkg || '').indexOf('.') != -1) && client[pkg] !== undefined) { 
    return client[pkg] 
  }

  if (((pkg || '').indexOf('.') != -1) && client[pkg] !== undefined) { 
    return client[pkg] 
  }
  
  const ls = pkg.split('.')
  let obj = client
  ls.forEach(function (name) {
    if (create) {
      obj[name] = obj[name] || {}
    }
    obj = obj[name]
  })
  console.log("obj is", obj)
  return obj
}
0reactions
WoLfuluscommented, Jul 9, 2018

When this will be published?

Read more comments on GitHub >

github_iconTop Results From Across the Web

problem with namespace · Issue #159 · golang/protobuf - GitHub
Your problem is that you're translating A.proto and B.proto separately. The plugin assumes that everything passed together is in the same ...
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to...
Read more >
How to fix "The type of namespace name "Fault" does not exist ...
Do this: Right click on your .proto file in the Visual Studio solution explorer. Choose "Properties"; Change "Build action" to "Protobuf ...
Read more >
protobuf avoid namespace conflict - Google Groups
Hi! I have two packages server and client. All belongs to different repos. In this packages i have internal/errors dir with errors.proto
Read more >
Troubleshoot gRPC on .NET Core - Microsoft Learn
Troubleshoot errors when using gRPC on .NET Core. ... gRPC C# assets are not code generated from .proto files.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found