avinassh / grpc-errors Goto Github PK
View Code? Open in Web Editor NEWA handy guide to gRPC errors
Home Page: http://avi.im/grpc-errors
License: MIT License
A handy guide to gRPC errors
Home Page: http://avi.im/grpc-errors
License: MIT License
I am using gRPC
in a project where I have to set and get values from some separate functions. Some functions has case that if the y get unwanted value they will throw runtime error
. By following your content I have got an idea to catch a error_state from inside of the gRPC function.
I am giving here some of my approach. Source is this
proto file where only including here the client message part
message NameQuerry {
string name = 1;
int32 cl_value = 2; // This is a user input data which will be passed to the server and then to a outside function
int main(int argc, char* argv[])
{
// Setup request
expcmake::NameQuerry query;
expcmake::Address result;
query.set_name("John");
int x;
cout << "give value of x: ";
cin>> x;
query.set_cl_value(x);
// remaining are as like as before
#include <iostream>
using namespace std;
void Check_Value(const ::expcmake::NameQuerry* request)
{
if (request->cl_value() < 5)
cout << "request->cl_value(): " << request->cl_value() << endl;
else
throw std::runtime_error("********** BAD VALUE **********");
}
class AddressBookService final : public expcmake::AddressBook::Service {
public:
virtual ::grpc::Status GetAddress(::grpc::ServerContext* context, const ::expcmake::NameQuerry* request, ::expcmake::Address* response)
{
std::cout << "Server: GetAddress for \"" << request->name() << "\"." << std::endl;
Check_Value(request);
// remaining are as like as before
After building the project if from client side 5
or greater than 5
is given server
didn't show any message but running continuously(which is obvious for the Wait
function of gRPC) where my expectation was it should print in server console
********** BAD VALUE **********
Though, in client side I have got all passed value as BLANK
where I can assume that, server
didn't perform any process after the runtime_error
.
So my query is:
1/ How can I see the runtime_error
message in server side console?
2/ Any gRPC default system
to pass this incident to the client (Any generic message).
Note:
In my real example this runtime_error
message related function is coming from another project where I cannot access to modify.
Given the update here: https://grpc.io/blog/grpc-csharp-future/ with gRPC.Core being phased out. Is there any chance the c# sample could be updated to the new gRPC-Dotnet? I believe it is mostly just a case of swapping out packages and namespaces (but could be wrong!).
This repo is much appreciated, it'd be great to have an update. If it isn't possible, I'll see if I can get a PR together at some point, but I can't promise anything at this point.
Kotlin gRPC exposes a different server endpoint API from Java. It would be useful to have an example of throwing a StatusException, if that's what the Kotlin generated code expects users to do.
With this in build.gradle
:
plugins {
id "com.google.protobuf" version "0.8.12"
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:3.12.2" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.29.0" }
grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:0.1.2" }
}
generateProtoTasks {
all()*.plugins {
grpc {}
grpckt {}
}
}
}
The generated RPC functions to override are like this:
/**
* Holder for Kotlin coroutine-based client and server APIs for
* my_pkg.MyService.
*/
object MyServiceGrpcKt {
...
/**
* Returns the response to an RPC for valohealth_monocle.model_search.ModelSearchService.Search.
*
* If this method fails with a [StatusException], the RPC will fail with the corresponding
* [io.grpc.Status]. If this method fails with a [java.util.concurrent.CancellationException],
* the RPC will fail
* with status `Status.CANCELLED`. If this method fails for any other reason, the RPC will
* fail with `Status.UNKNOWN` with the exception as a cause.
*
* @param request The request from the client.
*/
open suspend fun search(request: ModelSearchRequest): ModelSearchResponse = throw
StatusException(UNIMPLEMENTED.withDescription("Method my_pkg.MyService.Search is unimplemented"))
}
So unlike Java, there's no observer
to tag errors onto, but the default implementation here seems to give an example of throwing an error.
Hi Avinassh,
I am trying to write a gRPC server in C++ on Linux platform .
Will i be able to communicate with this server from remote windows machine using a C# client?
see note https://godoc.org/google.golang.org/grpc#Errorf
i think the devs just moved the functionality into a separate sub-package https://godoc.org/google.golang.org/grpc/status
Theses examples are great! I wish that the grpc project would fold them into the standard language quick start or tutorials.
I see that the examples seem to focus on setting the error code and message, but the Status now supports additional details: https://godoc.org/google.golang.org/grpc/status#Status.Details.
Have you considered extending the examples to show how to set and retrieve these details? I'm personally interested in Python and Go at the moment, but I guess you'd want to expand all of the examples at once.
Hi
Thank you for your nice lib!
Can you please also provide an example in Java?
For Java, something like grpc/grpc-java#1552 (comment) .
For Kotlin, it currently has to be different: grpc/grpc-kotlin#141 (comment) .
It would also be great to mention these in the gRPC error docs: https://grpc.io/docs/guides/error/ .
Specifically, I'm looking for how to properly close a streaming RPC with an error code/status in a Node server.
It would be really nice to have some examples of how to return errors from a streaming API.
I have a requirement in my project to work with openssl 1.0.2u version.
How to install grpc with openssl version 1.0.2u?
I am trying to extract the "details" portion of a gRPC error using Python as the client language. The core protobuf definition that I am basing the behavior on is documented here. Example client code block:
try:
response = client.Create(req, timeout=30)
print(response)
except grpc._channel._InactiveRpcError as e:
print("caught as inactive RPC error")
print(e.__class__)
print(e.details.__class__)
print(e.details)
I was expected the details to be the extended content rather than the error message. Am I overlooking something obvious? Is this not supported in the Python client library?
The server-side code is written in go and looks something like this:
s := status.New(codes.AlreadyExists, "dataset already exists for combination of subject and provenance")
if s, err = s.WithDetails(res.VersionSets[0]); err != nil {
logrus.Panicf("cannot add details to google.rpc.Status: %+v", err)
}
return nil, s.Err()
Hello everyone!
It would be great to have examples for PHP, right?
I know it's mentioned here #4, but I want to make things move!
Unfortunately I don't know PHP, does someone knows how it works or have found an example on the internet ? (I did not)
Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.