tag:robotlegs.tenderapp.com,2009-10-18:/discussions/suggestions/59-better-error-handlingRobotlegs: Discussion 2018-10-18T16:35:27Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/73359592011-05-19T19:27:42Z2011-05-19T19:36:37ZBetter error handling <div><p>Hi Kevin,</p>
<p>not so much lack of understanding of the architecture as just
bumping into the really weak spot in the AS3 event model.</p>
<p>Imagine the following:</p>
<ol>
<li>
<p>Two (or more) different event classes use the same string in one
of their events</p>
<p><code>SomeEvent.COMPLETE = "Complete";</code></p>
<p><code>SomeServiceEvent.SERVICE_COMPLETE = "Complete";</code></p>
</li>
<li>
<p>Both these events are mapped in the command map:</p>
<p><code>commandMap.mapEvent(SomeEvent.COMPLETE, DoSomething,
SomeEvent);</code>
<code>commandMap.mapEvent(SomeServiceEvent.SERVICE_COMPLETE,
DoSomethingElse, SomeServiceEvent);</code></p>
</li>
</ol>
<p>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.</p>
<p>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
<code>SomeEvent.COMPLETE</code> or
<code>SomeServiceEvent.SERVICE_COMPLETE</code>.</p>
<p>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.</p>
<p>Here's a quick run through of other strategies that wouldn't
work:</p>
<ol>
<li>
<p>Checking whether the type passed is a property of the event
class given...</p>
<p>... 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.</p>
</li>
<li>
<p>Warning when an event doesn't end up getting mapped to a
command...</p>
<p>... 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.</p>
</li>
</ol>
<p>So - as you can see, it's not actually feasible (at least not in
a way I can see - I might be missing something).</p>
<p>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.</p>
<p>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).</p>
<p>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.</p>
<p>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.</p>
<p>Cheers,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/73359592011-05-20T15:25:36Z2011-05-20T15:25:38ZBetter error handling <div><p>Hey Stray,</p>
<p>That makes a lot of sense and is pretty much what I suspected. I
guess I could try paying more attention. :)</p>
<p>Thanks!</p></div>kevin.suttle