Better error message when given a wrong value for address to connectUNIX

[email protected]
Newsgroups gmane.comp.python.twisted.bugs
Message-ID <[email protected]>
New submission from psykidellic <None>:

So I had to write XMLRPC server client working on unix domain socket. This is how I implemented the server and client:

{{{
from twisted.application import internet, service
from twisted.web import xmlrpc, server
from inotify import INotify

class Example(xmlrpc.XMLRPC):
    """An example object to be published."""

    def xmlrpc_echo(self, x):
        """
        Return all passed args.
        """
        return x

    def xmlrpc_add(self, a, b):
        """
        Return sum of arguments.
        """
        return a + b

    def xmlrpc_fault(self):
        """
        Raise a Fault indicating that the procedure should not be used.
        """
        raise xmlrpc.Fault(123, "The fault procedure is faulty.")

application = service.Application('xxxx')
internet.UNIXServer('/tmp/tfin.sock', factory=server.Site(r)).setServiceParent(
        service.IServiceCollection(application))

>>>>

from twisted.web.xmlrpc import Proxy
from twisted.internet import reactor

class UnixProxy(Proxy):
    """
    Call remote XML-RPC C{method} with given arguments.
    The server is listening on a Unix domain socket.
    Based on: 
    http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/twisted/web/xmlrpc.py

    @return: a L{defer.Deferred} that will fire with the method response,
        or a failure if the method failed. Generally, the failure type will
        be L{Fault}, but you can also have an C{IndexError} on some buggy
        servers giving empty responses.
    """
    def callRemote(self, method, *args):
        factory = self.queryFactory(
            self.path, self.host, method, self.user,
            self.password, self.allowNone, args)
        reactor.connectUNIX(self.host, factory=factory)
        
        return factory.deferred

def printValue(value):
    print repr(value)
    reactor.stop()

def printError(error):
    print 'error', error
    reactor.stop()

proxy = UnixProxy('/tmp/tfin.sock')
proxy.callRemote('add', 3, 5).addCallbacks(printValue, printError)
reactor.run()
}}}

Running the client, I got:

{{{
error [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectError'>: An error occurred while connecting: 22: Invalid argument.
]
}}}

On further dicussion with exarkun on IRC and looking at the problem, it seems that *host* value is mangled on Proxy __init__. The correct value is actually kept in *self.path*. Passing self.path to connectUNIX worked like a charm.

Though a better error message could have been provided.

----------
Type     : enhancement
Component: core
Keywords : 
Priority : normal
Nosy     : 
----------
http://twistedmatrix.com/trac/ticket/3805
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.