Skip to content

gRPC error messages are not the same as API error messages #1378

Closed

Description

@susanlinsfu

I have this code:

app.get('/testing', function(req, res) {

    var cachedTransaction;
    datastore.runInTransaction(function(transaction, done) {
        cachedTransaction = transaction;
        transaction.save([{
            key: datastore.key([config.USER_TABLE, 'B']),
            method: 'insert',
            data: [{
                name: 'e',
                value: 'B'
            }, {
                name: 'p',
                value: 'B',
                excludeFromIndexes: true
            }]
        }, {
            key: datastore.key([config.ANOTHER_TABLE, 'B']),
            method: 'insert',
            data: {
                name: 'u',
                value: 'B'
            }
        }, {
            key: datastore.key([config.YET_ANOTHER_TABLE, 'B']),
            method: 'insert',
            data: [{
                name: 'a',
                value: 'a'
            }, {
                name: 'b',
                value: 'b'
            }]
        }]);

        done();
    }, function(err) {
        if (!err) {
            console.log('no error!');
            return;
        }
        if ('' + err === 'Error: entity already exists') {
            console.log('Entity alreaady exists!');
            return;
        }
        console.log('Some other error. The error = ' + JSON.stringify(err));
        return;
    });
});

What is happening is I call this url the first time and it inserts the entities it needs to into the 3 tables. I call it again, but as you can see when I call it again I am trying to insert the same 3 entities with the same key and this is not allowed, but this is exactly what I am testing. So I am expecting the error message of Error: entity already exists as it has in the past.

I wrote this code maybe 4 months ago and I am unsure of what gcloud-node version I was using, but it was then returning this error message on a duplicate. Since then I have updated my gcloud-node libraries and currently using 0.34.0. The output now when I try to insert a duplicate entity into the production datastore is now this:

Some other error. The error = {"code":400,"metadata":{"_internal_repr":{}}}

My goal is to capture and to present to the user if they are inserting a duplicate entity, which with my code I have been able to in the past, but now I am unable to after testing it again tonight after some time. I was wondering if anything has changed to cause this or if I am missing something?

Cheers

Activity

  1. changed the title [-]datastore - Existing entity error message?[/-] [+]gRPC error messages are not the same as API error messages[/+] on Jun 13, 2016
  2. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Jun 13, 2016
  3. stephenplusplus commented on Jun 13, 2016

    @stephenplusplus
    Contributor

    We're having an issue getting Datastore's intelligent error reporting through the request library we're using, gRPC. I'm not sure which layer to place the fault, but @pcostell is looking into it.

  4. pcostell commented on Jun 13, 2016

    @pcostell
    Contributor

    @stephenplusplus Can we re-open this over on the Datastore side? This is actually an issue with the protocol -- gRPC sends error messages via headers and many of our error messages contain pretty-printed protos which include new lines which cannot be included so the whole message gets stripped.

    We are evaluating switching to use Status.detail to pass this information instead.

  5. stephenplusplus commented on Jun 13, 2016

    @stephenplusplus
    Contributor

    That makes sense. Are there any public discussions that we can subscribe to? Until it is supported upstream, this issue works fine for our tracking purposes.

  6. eddavisson commented on Jul 6, 2016

    @eddavisson

    Has it been confirmed that this only affects error messages with newlines? I was trying to repro this Stack Overflow issue and seem to be getting similar behavior without a newline.

    To reproduce:

    1. Follow the "Installation and Setup" instructions for node.js here.
    2. Modify line 71 of tasks.js to use a reserved kind (e.g. __kind__).
    3. Run node tasks.js new foo.

    I get:

    $ node tasks.js  new foo
    .../nodejs-docs-samples-master/datastore/tasks.js:172
              throw err;
              ^
    
    Error: Bad Request
        at .../nodejs-docs-samples-master/datastore/node_modules/grpc/src/node/src/client.js:417:17
    

    The expected error is (got this from APIs Explorer):

    {
     "error": {
      "code": 400,
      "message": "The kind \"__kind__\" is reserved.",
      "status": "INVALID_ARGUMENT",
     }
    }
    
    
  7. stephenplusplus commented on Jul 7, 2016

    @stephenplusplus
    Contributor

    @eddavisson I believe the problem is that the error details aren't being given to us via the transport layer, gRPC. Patrick's comment here elaborates on that: #1378 (comment)

    Let me know if I'm missing something and there's a bug in this library.

  8. stephenplusplus commented on Jul 15, 2016

    @stephenplusplus
    Contributor

    This issue turned out to be 2 parts:

    1. We are overwriting the raw gRPC error message -- FIXED!
    2. Datastore isn't returning the same error message it does in the JSON API through the gRPC API.

    We'll keep this open to track part 2.

  9. eddavisson commented on Jul 18, 2016

    @eddavisson

    Note that we believe (2) only applies to error messages that contain newlines. We also believe it's a gRPC-wide issue. Still working an appropriate issue that we can de-dupe this to.

  10. eddavisson commented on Aug 11, 2016

    @eddavisson

    Moving over to the Cloud Datastore API tracker (though this is ultimately a gRPC-wide issue).

    Duplicate of googleapis/google-cloud-datastore#132

  11. added a commit that references this issue on Feb 26, 2026
    b52282f
  12. added a commit that references this issue on Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

coretype: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions