osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.65k stars 697 forks source link

Consider using grpc error codes for grpc API responses #2837

Open jvgutierrez opened 1 month ago

jvgutierrez commented 1 month ago

Hi, I've realized that gobgp grpc API doesn't make use of grpc status codes when returning errors, so clients need to parse the status message string to be able which kind of error received instead of just checking the status code.

So instead of

    if _, err := client.DeletePolicy(ctx, policyRequest); status.Code(err) != codes.NotFound {
        // handle error
    }   

The client needs to check the status string:

    if _, err := client.DeletePolicy(ctx, policyRequest); err != nil {
        s, ok := status.FromError(err)
        if !ok || !strings.HasPrefix(s.Message(), "not found") {
            // handle error
        }
    }

Would it be feasible to adopt grpc status codes? Thanks!

SkalaNetworks commented 3 weeks ago

Is that an API breaking change with the need for a rollout of a v4?