Code Monkey home page Code Monkey logo

grpc-errors's Introduction

gRPC Errors - A handy guide to gRPC errors.

This repository contains code examples in different languages which demonstrate handling errors in gRPC.

Check the hello.proto file to see the gRPC method definitions. It has two methods SayHello and SayHelloStrict:

func SayHello(name) {
    return "Hey, (name)!"
}

SayHelloStrict is similar, but throws an error if the length of name is more than 10 characters.

Each language directories have instructions to generate gRPC methods in respective languages. I assume that you have done the basic tutorials.

Guide

Check this page for quick guide and examples of all languages - gRPC Errors

System Requirements

License

The mighty MIT license. Please check LICENSE for more details.

grpc-errors's People

Contributors

avinassh avatar dannyfeliz avatar r-marques avatar wichert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grpc-errors's Issues

Replacing gRPC.Core with gRPC.Dotnet

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.

How to detect external runtime_error message by gRPC server and pass to client

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

client/src/main.cpp

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

server/src/main.cpp

#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.

Node Streaming Error

It would be really nice to have some examples of how to return errors from a streaming API.

Adding examples of Status Details in addition to Code and Message?

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.

Java implementation

Hi
Thank you for your nice lib!
Can you please also provide an example in Java?

PHP implementation

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!

Is it possible to extract extended gRPC details from Python exception?

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()

Kotlin implementation

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.