Skip to content
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
2 changes: 1 addition & 1 deletion varlink/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _next_varlink_message(self):

if "error" in message and message["error"] is not None:
self._in_use = False
e = VarlinkError.new(message, self._namespaced)
e = VarlinkError.new(message)
raise e
else:
return message["parameters"], ("continues" in message) and message["continues"]
Expand Down
3 changes: 3 additions & 0 deletions varlink/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def new(cls, message, namespaced=False):
elif message["error"] == "org.varlink.service.MethodNotImplemented":
return MethodNotImplemented.new(message, namespaced)

elif message["error"] == "org.varlink.service.MethodNotFound":
return MethodNotFound.new(message, namespaced)

else:
return cls(message, namespaced)

Expand Down
34 changes: 34 additions & 0 deletions varlink/tests/test_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json
import unittest

import varlink


class OneMessageClientHandler(varlink.ClientInterfaceHandler):
def __init__(self, interface, namespaced, next_message):
# No interface but we do not use them
super().__init__(interface, namespaced)
self.next_message = next_message

def _next_message(self):
yield self.next_message


class TestError(unittest.TestCase):
def test_pack_unpack(self):
dummy_if = varlink.Interface("interface org.example.dummy")
for error in [
varlink.InterfaceNotFound("org.varlink.notfound"),
varlink.MethodNotFound("Method"),
varlink.MethodNotImplemented("Abstract"),
varlink.InvalidParameter("Struct.param"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this doesn't differentiate for namespaced, while that is an accepted argument in VarlinkError.__init__.

Now that isn't something which will happen in practice but its a bit confusing. Also note VarlinkError has parameters() which does have namespaced support.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the goal here was to test the client handling of those errors, not the Errors serialization which is supposed to be the same whether the error is namespaced or not (although that could be an interesting test as well).

]:
for namespaced in (True, False):
with self.subTest(error=error, namespaced=namespaced):
# encode error
encoded = json.dumps(error, cls=varlink.VarlinkEncoder)

# Emulates the client receiving an error
handler = OneMessageClientHandler(dummy_if, namespaced, encoded)
with self.assertRaises(error.__class__):
handler._next_varlink_message()