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

Fix retrieving error messages #274

Merged
merged 1 commit into from
Jun 3, 2021
Merged
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
4 changes: 2 additions & 2 deletions txmongo/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from twisted.python.compat import StringType
from txmongo.database import Database
from txmongo.protocol import MongoProtocol, Query
from txmongo.utils import timeout
from txmongo.utils import timeout, get_err

DEFAULT_MAX_BSON_SIZE = 16777216
DEFAULT_MAX_WRITE_BATCH_SIZE = 1000
Expand Down Expand Up @@ -103,7 +103,7 @@ def configure(self, proto):
# Make sure the command was successful.
if not config.get("ok"):
code = config.get("code")
msg = "TxMongo: " + config.get("err", "Unknown error")
msg = "TxMongo: " + get_err(config, "Unknown error")
raise OperationFailure(msg, code)

# Check that the replicaSet matches.
Expand Down
3 changes: 2 additions & 1 deletion txmongo/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from twisted.internet import defer, protocol, error
from twisted.python import failure, log
from twisted.python.compat import unicode
from txmongo.utils import get_err


if PY3:
Expand Down Expand Up @@ -449,7 +450,7 @@ def on_reply(reply):
assert len(reply.documents) == 1

document = reply.documents[0].decode()
err = document.get("err", None)
err = get_err(document, None)
code = document.get("code", None)

if err is not None:
Expand Down
6 changes: 6 additions & 0 deletions txmongo/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ def on_fail(failure):
def check_deadline(_deadline):
if _deadline is not None and _deadline < time():
raise TimeExceeded("TxMongo: now '{0}', deadline '{1}'".format(time(), _deadline))


def get_err(document, default=None):
err = document.get("err", None) or document.get("codeName", None)
errmsg = document.get("errmsg", None)
return ": ".join(filter(None, (err, errmsg))) or default