You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/09/11 13:12:30 UTC

[tinkerpop] branch TINKERPOP-2285 updated (394dd2b -> fefd654)

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a change to branch TINKERPOP-2285
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git.


 discard 394dd2b  TINKERPOP-2285 Added ResponseError in gremlin-javascript
     new fefd654  TINKERPOP-2285 Added ResponseError in gremlin-javascript

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (394dd2b)
            \
             N -- N -- N   refs/heads/TINKERPOP-2285 (fefd654)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 docs/src/upgrade/release-3.3.x.asciidoc | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)


[tinkerpop] 01/01: TINKERPOP-2285 Added ResponseError in gremlin-javascript

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2285
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit fefd6544dc5907be8c663ee2ee0bde9bf3a7d79f
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Wed Sep 11 08:56:40 2019 -0400

    TINKERPOP-2285 Added ResponseError in gremlin-javascript
    
    ResponseError in javascript is akin to ResponseException in java. It includes more direct access to protocol lever server error information such as the status code and status attributes which means we don't need to pack that information into the error message itself at all. Kept that old style to the error messages just in case users were parsing those in prior versions - didn't want to break that.
---
 CHANGELOG.asciidoc                                 |  1 +
 docs/src/upgrade/release-3.3.x.asciidoc            | 23 +++++++++++++++
 .../gremlin-javascript/lib/driver/connection.js    | 12 +++++---
 .../lib/driver/response-error.js                   | 33 ++++++++++++++++++++++
 .../test/integration/remote-connection-tests.js    |  5 ++++
 5 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 366d759..45c3bb2 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-3-9]]
 === TinkerPop 3.3.9 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Exposed response status attributes in a `ResponseError` in gremlin-javascript.
 * Added `ImmutableExplanation` for a `TraversalExplanation` that just contains data.
 * Fixed `TraversalExplanation` deserialization in GraphSON 2 and 3 which was not supported before in Java.
 * Added support for custom request headers in Python.
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index 5cd0a01..b1dfcbd 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -21,6 +21,29 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 *Gremlin Symphony #40 in G Minor*
 
+== TinkerPop 3.3.9
+
+*Release Date: NOT OFFICIALLY RELEASED YET*
+
+Please see the link:https://github.com/apache/tinkerpop/blob/3.3.8/CHANGELOG.asciidoc#release-3-3-9[changelog] for a complete list of all the modifications that are part of this release.
+
+=== Upgrading for Users
+
+==== Javascript ResponseError
+
+Gremlin Javascript now enables more robust error handling by way of a `ResponseError` which provides access to more
+information from the server. Specifically, it includes the `statusMessage` and `statusCode` which were formerly packed
+into the `Error.message` property, which meant that the error message string had to be parsed if there was a need to
+take a specific action based on that information. The `ResponseError` also includes the `statusAttributes` which
+is a `Map` object that will typically incorporate server `exceptions` and `stackTrace` keys, but could also include
+provider specific error information.
+
+The original error messaging has remained unchanged and therefore users who were message parsing should not expect
+changes in behavior, however, future versions will eliminate the "overuse" of the `Error.message` property, so it is
+advised that users update their code to take advantage of the `ResponseError` features.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-2285[TINKERPOP-2285]
+
 == TinkerPop 3.3.8
 
 *Release Date: August 5, 2019*
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
index 0ae340c..5b8cd89 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/connection.js
@@ -28,6 +28,7 @@ const util = require('util');
 const utils = require('../utils');
 const serializer = require('../structure/io/graph-serializer');
 const ResultSet = require('./result-set');
+const ResponseError = require('./response-error');
 
 const responseStatusCode = {
   success: 200,
@@ -235,10 +236,12 @@ class Connection extends EventEmitter {
         this._clearHandler(requestId);
         if (response.status !== undefined && response.status.message) {
           return handler.callback(
-            new Error(util.format(
-              'Server error (no request information): %s (%d)', response.status.message, response.status.code)));
+            // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
+            new ResponseError(util.format(
+              'Server error (no request information): %s (%d)', response.status.message, response.status.code), response.status));
         } else {
-          return handler.callback(new Error(util.format('Server error (no request information): %j', response)));
+           // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
+          return handler.callback(new ResponseError(util.format('Server error (no request information): %j', response), response.status));
         }
       });
       return;
@@ -262,7 +265,8 @@ class Connection extends EventEmitter {
     else if (response.status.code >= 400) {
       // callback in error
       return handler.callback(
-        new Error(util.format('Server error: %s (%d)', response.status.message, response.status.code)));
+        // TINKERPOP-2285: keep the old server error message in case folks are parsing that - fix in a future breaking version
+        new ResponseError(util.format('Server error: %s (%d)', response.status.message, response.status.code), response.status));
     }
     switch (response.status.code) {
       case responseStatusCode.noContent:
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/response-error.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/response-error.js
new file mode 100644
index 0000000..5b5e4b6
--- /dev/null
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/response-error.js
@@ -0,0 +1,33 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+'use strict';
+
+class ResponseError extends Error {
+    constructor(message, responseStatus) {
+        super(message);
+        this.name = "ResponseError";
+        this.statusCode = responseStatus.code;
+        this.statusMessage = responseStatus.message;
+        this.statusAttributes = responseStatus.attributes || {};
+    }
+}
+
+
+module.exports = ResponseError;
\ No newline at end of file
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js
index b73d909..f86e252 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js
@@ -53,6 +53,11 @@ describe('DriverRemoteConnection', function () {
         .catch(function (err) {
           assert.ok(err);
           assert.ok(err.message.indexOf('599') > 0);
+          assert.ok(err.statusCode === 599);
+          assert.ok(err.statusMessage === 'Could not locate method: GraphTraversalSource.SYNTAX_ERROR()');
+          assert.ok(err.statusAttributes);
+          assert.ok(err.statusAttributes.has('exceptions'));
+          assert.ok(err.statusAttributes.has('stackTrace'));
         });
     });
   });