OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

gRPC InvalidArgument or FailedPrecondition if system cannot be updated

  • Thread starter Thread starter Paul Slevin
  • Start date Start date
P

Paul Slevin

Guest
Suppose we have a gRPC DB-backed application with some resource X like this, for example in Go:

Code:
type X struct {
    id      string
    name    string
    version string
}

And for some reason the application does not permit updates unless version = "2".

If a client tries to make a request to update the name of an existing resource whose version = "1", like this:

Code:
// This exists in the DB.
x := X{
    id:      "xyz",
    version: "1",
    name:    "some name",
}

UpdateX(
    X{
        id:      "xyz",
        name:    "some other name",
    },
)

what gRPC error code should be returned?

Referring to the codes here: https://grpc.github.io/grpc/core/md_doc_statuscodes.html, I can see arguments for both INVALID_ARGUMENT and FAILED_PRECONDITION.

INVALID_ARGUMENT:

  • The resource cannot be updated so the request will always fail, and is hence invalid

FAILED_PRECONDITION:

  • The state of the system needs to be checked to see what the version of the resource is, you can't determine a priori whether the request is possible
  • Even though the system currently does not allow such updates, in theory it could be updated so that the request becomes acceptable
<p>Suppose we have a gRPC DB-backed application with some resource <code>X</code> like this, for example in Go:</p>
<pre><code>type X struct {
id string
name string
version string
}

</code></pre>
<p>And for some reason the application does not permit updates unless <code>version = "2"</code>.</p>
<p>If a client tries to make a request to update the name of an existing resource whose <code>version = "1"</code>, like this:</p>
<pre><code>// This exists in the DB.
x := X{
id: "xyz",
version: "1",
name: "some name",
}

UpdateX(
X{
id: "xyz",
name: "some other name",
},
)
</code></pre>
<p>what gRPC error code should be returned?</p>
<p>Referring to the codes here: <a href="https://grpc.github.io/grpc/core/md_doc_statuscodes.html" rel="nofollow noreferrer">https://grpc.github.io/grpc/core/md_doc_statuscodes.html</a>, I can see arguments for both INVALID_ARGUMENT and FAILED_PRECONDITION.</p>
<p>INVALID_ARGUMENT:</p>
<ul>
<li>The resource cannot be updated so the request will always fail, and is hence invalid</li>
</ul>
<p>FAILED_PRECONDITION:</p>
<ul>
<li>The state of the system needs to be checked to see what the version of the resource is, you can't determine a priori whether the request is possible</li>
<li>Even though the system currently does not allow such updates, in theory it could be updated so that the request becomes acceptable</li>
</ul>
I have found how to fix this.
 
Top