Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FysomError raised from FysomGlobal lacks sufficient context #45

Open
frank-pet opened this issue Jan 2, 2024 · 1 comment
Open

FysomError raised from FysomGlobal lacks sufficient context #45

frank-pet opened this issue Jan 2, 2024 · 1 comment

Comments

@frank-pet
Copy link

FysomErrors raised from FysomGlobal contain the same information as those raised from Fysom. FysomError instances need to include an attribute ('obj' ?) that contains the object instance of the FysomMixin from which the exception is raised. Custom handlers (try..except FysomError as err:) can then format more helpful debugging information.

This should be a straightforward fix by adding an instance= kwarg to the FysomError constructor. And, there are only a very few places in FysomGlobal where the error is raised.

@frank-pet
Copy link
Author

Here are the changes to implement this issue:
--- a/src/main/python/fysom/init.py
+++ b/src/main/python/fysom/init.py
@@ -58,9 +58,10 @@ class FysomError(Exception):
in case of sharing event data.
'''

  • def init(self, msg, event=None):
  • def init(self, msg, event=None, instance=None):
    super(FysomError, self).init(msg)
    self.event = event
  •    self.instance = instance
    

class Canceled(FysomError):
@@ -586,7 +587,7 @@ class FysomGlobal(object):
if not self.can(obj, event):
raise FysomError(
'event %s inappropriate in current state %s'

  •                % (event, self.current(obj)))
    
  •                % (event, self.current(obj)), instance=obj)
    
           # Prepare the event object with all the meta data to pas through.
           # On event occurrence, source will always be the current state.
    

@@ -612,14 +613,14 @@ class FysomGlobal(object):
raise Canceled(
'Cannot trigger event {0} because the {1} '
'condition not returns {2}'.format(

  •                            event, cond, target), e
    
  •                            event, cond, target), e, instance=obj
                       )
    
           # try to trigger the before event, unless it gets cancelled.
           if self._before_event(obj, e) is False:
               raise Canceled(
                   'Cannot trigger event {0} because the onbefore{0} '
    
  •                'handler returns False'.format(event), e)
    
  •                'handler returns False'.format(event), e, instance=obj)
    
           # wraps the activities that must constitute a single transaction
           if self.current(obj) != e.dst:
    

@@ -717,5 +718,5 @@ class FysomGlobal(object):
def trigger(self, obj, event, *args, **kwargs):
if not hasattr(self, event):
raise FysomError(

  •            "There isn't any event registered as %s" % event)
    
  •            "There isn't any event registered as %s" % event, instance=obj)
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant