Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestKit: add unified error class mappings #707

Draft
wants to merge 1 commit into
base: 5.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions testkitbackend/_async/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)

from . import requests
from .. import totestkit
from .._driver_logger import (
buffer_handler,
log,
Expand Down Expand Up @@ -103,24 +104,10 @@ async def write_driver_exc(self, exc):
key = self.next_key()
self.errors[key] = exc

payload = {"id": key, "msg": ""}

if isinstance(exc, MarkdAsDriverException):
wrapped_exc = exc.wrapped_exc
payload["errorType"] = str(type(wrapped_exc))
if wrapped_exc.args:
payload["msg"] = str(wrapped_exc.args[0])
else:
payload["errorType"] = str(type(exc))
if isinstance(exc, Neo4jError) and exc.message is not None:
payload["msg"] = str(exc.message)
elif exc.args:
payload["msg"] = str(exc.args[0])

if isinstance(exc, Neo4jError):
payload["code"] = exc.code

await self.send_response("DriverError", payload)
await self.send_response("DriverError", {
**totestkit.error(exc),
"id": key,
})

async def _process(self, request):
""" Process a received request by retrieving handler that
Expand Down
23 changes: 5 additions & 18 deletions testkitbackend/_sync/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)

from . import requests
from .. import totestkit
from .._driver_logger import (
buffer_handler,
log,
Expand Down Expand Up @@ -103,24 +104,10 @@ def write_driver_exc(self, exc):
key = self.next_key()
self.errors[key] = exc

payload = {"id": key, "msg": ""}

if isinstance(exc, MarkdAsDriverException):
wrapped_exc = exc.wrapped_exc
payload["errorType"] = str(type(wrapped_exc))
if wrapped_exc.args:
payload["msg"] = str(wrapped_exc.args[0])
else:
payload["errorType"] = str(type(exc))
if isinstance(exc, Neo4jError) and exc.message is not None:
payload["msg"] = str(exc.message)
elif exc.args:
payload["msg"] = str(exc.args[0])

if isinstance(exc, Neo4jError):
payload["code"] = exc.code

self.send_response("DriverError", payload)
self.send_response("DriverError", {
**totestkit.error(exc),
"id": key,
})

def _process(self, request):
""" Process a received request by retrieving handler that
Expand Down
18 changes: 13 additions & 5 deletions testkitbackend/test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV4x3.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV3.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV4x1.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV3.test_should_retry_on_auth_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV5x0.test_should_fail_on_token_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV4x3.test_should_fail_on_token_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV3.test_should_fail_on_token_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV4x1.test_should_fail_on_token_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.authorization.test_authorization.TestAuthorizationV3.test_should_fail_on_token_expired_on_begin_using_tx_function":
"Flaky: test requires the driver to contact servers in a specific order",
"stub.session_run_parameters.test_session_run_parameters.TestSessionRunParameters.test_empty_query":
"Driver rejects empty queries before sending it to the server",
"stub.server_side_routing.test_server_side_routing.TestServerSideRouting.test_direct_connection_with_url_params":
"Driver emits deprecation warning. Behavior will be unified in 6.0."
"Driver emits deprecation warning. Behavior will be unified in 6.0.",
"stub.routing.test_routing_v5x0.RoutingV5x0.test_should_fail_when_driver_closed_using_session_run":
"Driver allows usage of a session after closing the driver. WHY? HOW? GOD NO!",
"stub.routing.test_routing_v4x4.RoutingV4x4.test_should_fail_when_driver_closed_using_session_run":
"Driver allows usage of a session after closing the driver. WHY? HOW? GOD NO!",
"stub.routing.test_routing_v4x1.RoutingV4x1.test_should_fail_when_driver_closed_using_session_run":
"Driver allows usage of a session after closing the driver. WHY? HOW? GOD NO!",
"stub.routing.test_routing_v3.RoutingV3.test_should_fail_when_driver_closed_using_session_run":
"Driver allows usage of a session after closing the driver. WHY? HOW? GOD NO!"
},
"features": {
"Feature:API:ConnectionAcquisitionTimeout": true,
Expand Down
85 changes: 85 additions & 0 deletions testkitbackend/totestkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@

import math

from neo4j import (
_exceptions as _neo_exc,
exceptions as neo_exc,
)
from neo4j.graph import (
Node,
Path,
Relationship,
)

from .exceptions import MarkdAsDriverException


def record(rec):
fields = []
Expand Down Expand Up @@ -90,3 +96,82 @@ def to(name, val):
return {"name": "Path", "data": path}

raise Exception("Unhandled type:" + str(type(v)))


_error_classifier = None


def _get_error_classifier():
global _error_classifier

if _error_classifier is not None:
return _error_classifier

_error_classifier = [

]


def error(exc):
payload = {}

if isinstance(exc, MarkdAsDriverException):
exc = exc.wrapped_exc

if isinstance(exc, neo_exc.Neo4jError) and exc.message is not None:
payload["msg"] = str(exc.message)
elif exc.args:
payload["msg"] = str(exc.args[0])
else:
payload["msg"] = ""

if isinstance(exc, neo_exc.Neo4jError):
payload["code"] = exc.code

error_type = str(type(exc))

if isinstance(exc, neo_exc.SessionExpired):
error_type = "session_expired_error"
elif isinstance(exc, neo_exc.IncompleteCommit):
error_type = "incomplete_commit_error"
elif isinstance(exc, neo_exc.ServiceUnavailable):
error_type = "service_unavailable_error"
elif isinstance(exc, neo_exc.NotALeader):
error_type = "not_leader_error"
elif isinstance(exc, neo_exc.ForbiddenOnReadOnlyDatabase):
error_type = "forbidden_on_read_only_database_error"
elif isinstance(exc, AttributeError):
error_type = "illegal_state_error"
elif isinstance(exc, neo_exc.TokenExpired):
error_type = "token_expired_error"
elif isinstance(exc, neo_exc.ResultNotSingleError):
error_type = "not_single_error"
elif isinstance(exc, neo_exc.ConfigurationError):
error_type = "invalid_configuration_error"
elif isinstance(exc, neo_exc.ResultConsumedError):
error_type = "result_consumed_error"
elif isinstance(exc, (TypeError, ValueError)):
error_type = "illegal_argument_error"
elif isinstance(exc, _neo_exc.BoltProtocolError):
error_type = "protocol_error"
elif isinstance(exc, neo_exc.TransactionError):
error_type = "transaction_error"
elif isinstance(exc, neo_exc.UnsupportedServerProduct):
error_type = "untrusted_server_error"
elif isinstance(exc, neo_exc.TransientError):
if exc.code == "Neo.ClientError.Security.AuthorizationExpired":
# we should probably not remap this error to TransientError in the
# driver...
error_type = "authorization_expired_error"
else:
error_type = "transient_error"
elif isinstance(exc, neo_exc.ClientError):
if exc.code and exc.code.startswith("Neo.ClientError.Security."):
# maybe there should be a SecurityError class...
error_type = "security_error"
else:
error_type = "client_error"

payload["errorType"] = error_type

return payload