Skip to content

Instantly share code, notes, and snippets.

@jsenin
Created March 1, 2022 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsenin/245097d8afcb90c76546d85fc5a57f84 to your computer and use it in GitHub Desktop.
Save jsenin/245097d8afcb90c76546d85fc5a57f84 to your computer and use it in GitHub Desktop.
py-asterisk error from ExceptionBase need to provide a message
# Asterisk/Util.py
class EventCollection(Logging.InstanceLogger):
'''
Utility class to allow grouping and automatic registration of event.
'''
def __init__(self, initial=None):
'''
If <initial> is not None, register functions from the list <initial>
waiting for events with the same name as the function.
'''
self.subscriptions = {}
self.log = self.getLogger()
if initial is not None:
for func in initial:
self.subscribe(func.__name__, func)
def subscribe(self, name, handler):
'''
Subscribe callable <handler> to event named <name>.
'''
if name not in self.subscriptions:
subscriptions = self.subscriptions[name] = []
else:
subscriptions = self.subscriptions[name]
if handler in subscriptions:
raise SubscriptionError # pylint: disable=W0710
subscriptions.append(handler)
(felix) jorge@penta:~$ ipython
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from Asterisk.Util import SubscriptionError
In [2]: SubscriptionError
Out[2]: Asterisk.Util.SubscriptionError
In [3]: raise SubscriptionError
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-d76b471ae3a5> in <module>
----> 1 raise SubscriptionError
TypeError: __init__() missing 1 required positional argument: 'error'
In [4]:
@jsenin
Copy link
Author

jsenin commented Mar 1, 2022

Suscribing two times the same handler for an event, a SubscriptionError without explanation will be raised

if handler in subscriptions:                                                     
            raise SubscriptionError  # pylint: disable=W0710       

this error need to have a message

# Asterisk/__init__.py

class BaseException(Exception):                            
   '''                                                    
   Base class for all py-Asterisk exceptions.             
   '''                                                    
                                                          
   _prefix = '(Base Exception)'                           
   _error = '(no error)'                                  
                                                          
   def __init__(self, error):                             
       self._error = error                                

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment