Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1913 49b1507fd -> d457d7cba
TINKERPOP-1913 GremlinServerError for python has status attributes now Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d457d7cb Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d457d7cb Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d457d7cb Branch: refs/heads/TINKERPOP-1913 Commit: d457d7cba5a4a136597127c2793014bafa47b843 Parents: 49b1507 Author: Stephen Mallette <[email protected]> Authored: Tue Sep 18 15:38:44 2018 -0400 Committer: Stephen Mallette <[email protected]> Committed: Tue Sep 18 15:38:44 2018 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../src/main/jython/gremlin_python/driver/protocol.py | 11 ++++++++--- .../src/main/jython/tests/driver/test_client.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d457d7cb/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 386f0d9..a151bc7 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -42,6 +42,7 @@ This release also includes changes from <<release-3-3-3, 3.3.3>>. * Modified remote traversals to retrieve status attributes from traversal side-effects. * Deprecated two `submit()`-related methods on the Java driver `Client` class. * Modified Java and Gremlin.Net `ResponseException` to include status code and status attributes. +* Modified Python `GremlinServerError` to include status attributes. * Modified the return type for `IGremlinClient.SubmitAsync()` to be a `ResultSet` rather than an `IReadOnlyCollection`. * Added `Client.submit()` overloads that accept per-request `RequestOptions`. * Added sparql-gremlin. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d457d7cb/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py b/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py index 96174e0..c8e3e4a 100644 --- a/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py +++ b/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py @@ -31,7 +31,13 @@ __author__ = 'David M. Brown ([email protected])' class GremlinServerError(Exception): - pass + def __init__(self, status): + super(GremlinServerError, self).__init__("{0}: {1}".format(status["code"], status["message"])) + self._status_attributes = status["attributes"] + + @property + def status_attributes(self): + return self._status_attributes @six.add_metaclass(abc.ABCMeta) @@ -95,5 +101,4 @@ class GremlinServerWSProtocol(AbstractBaseProtocol): return status_code else: del results_dict[request_id] - raise GremlinServerError( - "{0}: {1}".format(status_code, message["status"]["message"])) + raise GremlinServerError(message["status"]) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d457d7cb/gremlin-python/src/main/jython/tests/driver/test_client.py ---------------------------------------------------------------------- diff --git a/gremlin-python/src/main/jython/tests/driver/test_client.py b/gremlin-python/src/main/jython/tests/driver/test_client.py index 44dc3a7..42e2c07 100644 --- a/gremlin-python/src/main/jython/tests/driver/test_client.py +++ b/gremlin-python/src/main/jython/tests/driver/test_client.py @@ -52,6 +52,16 @@ def test_client_eval_traversal(client): assert len(client.submit('g.V()').all().result()) == 6 +def test_client_error(client): + try: + # should fire an exception + client.submit('1/0').all().result() + assert False + except GremlinServerError as ex: + assert 'exceptions' in ex.status_attributes + assert 'stackTrace' in ex.status_attributes + + def test_client_bytecode(client): g = Graph().traversal() t = g.V()
