Better error handling

kevin.suttle's Avatar

kevin.suttle

19 May, 2011 07:02 PM

I'd love to know when I've forgotten to map a command (not sure how this is possible though)
or when I do stupid stuff like this:

commandMap.mapEvent(StatusEditModeToggleEvent.STATUS_EDIT_MODE_TOGGLED, StatusEditModeToggledCommand, StatusUpdateEvent);

Notice the 1st and 3rd params don't match, but at runtime there is never an error thrown. It could just be from my lack of understanding of the architecture.

Thanks!

  1. Support Staff 1 Posted by Stray on 19 May, 2011 07:27 PM

    Stray's Avatar

    Hi Kevin,

    not so much lack of understanding of the architecture as just bumping into the really weak spot in the AS3 event model.

    Imagine the following:

    1. Two (or more) different event classes use the same string in one of their events

      SomeEvent.COMPLETE = "Complete";

      SomeServiceEvent.SERVICE_COMPLETE = "Complete";

    2. Both these events are mapped in the command map:

      commandMap.mapEvent(SomeEvent.COMPLETE, DoSomething, SomeEvent); commandMap.mapEvent(SomeServiceEvent.SERVICE_COMPLETE, DoSomethingElse, SomeServiceEvent);

    The purpose of our third parameter here is to make sure that when one of these events is received, only the correct command (and not both) is executed.

    Now - when the mapping is made, the command map only receives a string for the first parameter - it has no idea whether this "complete" is was set using the static property SomeEvent.COMPLETE or SomeServiceEvent.SERVICE_COMPLETE.

    So - I'm not sure how we could even do this, but if we did it would still be problematic because you would no longer be able to use events with the same String - and unfortunately lots of existing utilities have string-clashes in their event naming.

    Here's a quick run through of other strategies that wouldn't work:

    1. Checking whether the type passed is a property of the event class given...

      ... won't work because if you want to create code that is flex-capable but not tied to the flex framework then you want to use the actual string (as we do in the mediatorMap) rather than the static property, and then just type it to plain'ol Event.

    2. Warning when an event doesn't end up getting mapped to a command...

      ... won't work because it might simply have been a string-clash issue, and maybe we're not interested in this event at all, it just has the same 'type' as the one we are interested in. It's 'right' that some events drop through the sieve.

    So - as you can see, it's not actually feasible (at least not in a way I can see - I might be missing something).

    All of this is partly down to the sucky string usage in the AS3 event model. Check out Signals - you might want to try those instead.

    However, thanks for bringing this up, because we've talked a little about Robotlegs 2 having some sort of code introspection tool with it that would be useful both for getting an overview of your architecture and for finding these kinds of errors - as well as injection point problems and so on (like trying to inject a private var).

    So - I'll add this to the list of things that are snagging people (and I totally understand the frustration of that - I make these kinds of mistakes too), and hopefully it's a fairly easy one to put into this tool.

    Shout them out if you have any other common-problems that code-introspection might help with. I'm talking about a text-parsing based tool, not a compiler, so things like non-matching 1st and 3rd parameters in command mappings are a good subject.

    Cheers,

    Stray

  2. 2 Posted by kevin.suttle on 20 May, 2011 03:25 PM

    kevin.suttle's Avatar

    Hey Stray,

    That makes a lot of sense and is pretty much what I suspected. I guess I could try paying more attention. :)

    Thanks!

  3. Stray closed this discussion on 25 May, 2011 08:01 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac