Commit ac89f2fa authored by Antoine Millet's avatar Antoine Millet
Browse files

Reworked exception tree.

RpcError are now reserved to rpc protocol, the RpcConnection uses the new
RpcConnectionError class.
parent 05136a3b
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -18,17 +18,17 @@ class RpcError(Exception):
        return '%s' % self.message
        return '%s' % self.message




class SocketRpcError(Exception):
class RpcConnectionError(Exception):


    '''
    '''
    Exception used internally to raise a socket fault.
    Base class for RpcConnection errors.
    '''
    '''




class RpcConnectionError(Exception):
class SocketError(RpcConnectionError):


    '''
    '''
    Base class for RpcConnection errors.
    Exception used internally to raise a socket fault.
    '''
    '''




+5 −5
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@ from uuid import uuid4


from threading import Event, Thread
from threading import Event, Thread


from sjrpc.core.exceptions import RpcError
from sjrpc.core.exceptions import RpcError, RpcConnectionError
from sjrpc.core.protocols import Protocol
from sjrpc.core.protocols import Protocol


__all__ = ['RpcProtocol']
__all__ = ['RpcProtocol']
@@ -208,12 +208,12 @@ class RpcProtocol(Protocol):
           Message must be a jsonisable structure.
           Message must be a jsonisable structure.
        '''
        '''


        #if not self._connected: #FIXME
        #    raise RpcError('SendError', 'disconnected from the peer')

        self.logger.debug('Sending: %s', message)
        self.logger.debug('Sending: %s', message)
        json_msg = json.dumps(message)
        json_msg = json.dumps(message)
        try:
            self._connection.send(self._label, payload=json_msg)
            self._connection.send(self._label, payload=json_msg)
        except RpcConnectionError as err:
            raise RpcError('RpcConnectionError', str(err))


    def _send_call(self, method_name, *args, **kwargs):
    def _send_call(self, method_name, *args, **kwargs):
        '''
        '''
+4 −4
Original line number Original line Diff line number Diff line
@@ -14,8 +14,8 @@ import logging
import threading
import threading


from sjrpc.core.protocols import Protocol, RpcProtocol, TunnelProtocol
from sjrpc.core.protocols import Protocol, RpcProtocol, TunnelProtocol
from sjrpc.core.exceptions import (RpcError, NoFreeLabelError,
from sjrpc.core.exceptions import (RpcConnectionError, NoFreeLabelError,
                                   FallbackModeEnabledError)
                                   FallbackModeEnabledError, SocketError)


import pyev
import pyev


@@ -293,7 +293,7 @@ class RpcConnection(object):
            except socket.error as err:
            except socket.error as err:
                errmsg = 'Fatal error while sending through socket: %s' % err
                errmsg = 'Fatal error while sending through socket: %s' % err
                self.logger.error(errmsg)
                self.logger.error(errmsg)
                raise RpcError('SocketError', errmsg)
                raise SocketError(errmsg)
            self._outbound_buffer = self._outbound_buffer[sent:]
            self._outbound_buffer = self._outbound_buffer[sent:]


        if not self._outbound_buffer:
        if not self._outbound_buffer:
@@ -334,7 +334,7 @@ class RpcConnection(object):
        '''
        '''
        self._event_fallback.wait()
        self._event_fallback.wait()
        if not self._connected:
        if not self._connected:
            raise RpcError('RpcError', 'Not connected to the peer')
            raise RpcConnectionError('Not connected to the peer')
        size = len(payload)
        size = len(payload)
        if self.fallback:
        if self.fallback:
            header = struct.pack(RpcConnection.MESSAGE_HEADER_FALLBACK, size)
            header = struct.pack(RpcConnection.MESSAGE_HEADER_FALLBACK, size)