diff --git a/contrib/plugins/helloworld.py b/contrib/plugins/helloworld.py index 1a5ede345676..3fb15ca0ef1a 100755 --- a/contrib/plugins/helloworld.py +++ b/contrib/plugins/helloworld.py @@ -19,6 +19,12 @@ def hello(plugin, name="world"): return s +@plugin.method("bye") +def bye(plugin, name, **kwargs): + """This methods requires {name} to be set by the caller !""" + return "Bye {}".format(name) + + @plugin.init() def init(options, configuration, plugin, **kwargs): plugin.log("Plugin helloworld.py initialized") diff --git a/contrib/pyln-client/pyln/client/plugin.py b/contrib/pyln-client/pyln/client/plugin.py index 0446300a625e..a2315217aaeb 100644 --- a/contrib/pyln-client/pyln/client/plugin.py +++ b/contrib/pyln-client/pyln/client/plugin.py @@ -83,9 +83,12 @@ def set_exception(self, exc): self._write_result({ 'jsonrpc': '2.0', 'id': self.id, - "error": "Error while processing {method}: {exc}".format( - method=self.method, exc=repr(exc) - ), + "error": { + "code": -32600, # "Invalid Request" + "message": "Error while processing {method}: {exc}" + .format(method=self.method, exc=repr(exc)), + # 'data' field "may be omitted." + }, }) def _write_result(self, result): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index f1cbc2e06dcb..f8d37ebe4256 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -180,6 +180,11 @@ def test_rpc_passthrough(node_factory): with pytest.raises(RpcError): n.rpc.fail() + # Try to call a method without enough arguments + with pytest.raises(RpcError, match="error: {'code': -32600, 'message': " + "'Error while processing bye"): + n.rpc.bye() + def test_plugin_dir(node_factory): """--plugin-dir works"""