Runtime warning when chaining Commands with the CommandSignal extension

willdady's Avatar


01 Nov, 2011 07:19 AM

I'm having an issue with the CommandSignal extension when attempting to chain signals together. I realise this has been raised before but I'm having issues with both the most recent versions of both RobotLegs (1.5.2) and the extension. I'm getting the runtime warning 'Warning: Injector already has a rule for type ...'.

The warning is occurring when one command triggers another command via a signal where BOTH commands require injections of the same type. Triggering the second command with a type not injected into the first results in no warning.

Any advice would be great!

  1. Support Staff 1 Posted by Stray on 01 Nov, 2011 08:56 AM

    Stray's Avatar

    Hi Will,

    It could mean your SignalCommandMap is out of date - it was leaving mappings lying around some time ago.

    Or - if you're definitely up to date, then it might be something you can ignore - it won't actually change the action, it just reports if it thinks something funny is going on. It all depends how your Signals are being chained - whether the next signal is firing before the mappings for the first have been cleaned up.


  2. 2 Posted by willdady on 01 Nov, 2011 12:03 PM

    willdady's Avatar

    Thanks Stray. I'm definitely using the latest versions of both.

    I've had a look at the source of SignalCommandMap and I think I understand what's happening. Technically the warning is correct in the case I've mentioned above because the signal's payload is mapped to the injector just before execute is called and then unmapped immediately afterwards.... as it should. The issue here is that we are triggering a second command INSIDE the first command's execute method and the triggering signal's payload is mapped BEFORE the first command's payload is unmapped... so thus there is a double-up in the injector. Again this is only an issue when both commands require an injection of the same type.

    A quick-and-dirty solution I've found is to modify the SignalCommandMap to expose the injector. Then, inside my first command I forcibly unmap that command's injections before triggering my next command. This stops the warning.

    I'm wondering if there is a more elegant solution to this which doesn't require modifying SignalCommandMap. I've noticed the vanilla Command class get's access to the injector but from what I can tell there is no way to get access to the child injector used by SignalCommandMap. I think either exposing the child injector in SignalCommandMap OR injecting the injector automatically into SignalCommand could be a solution.

    I realise this is 'just a warning' and the code continues to execute properly I just think If it could be avoided altogether that would stop a lot of confusion.

    Stray I'd love to hear your thoughts on this :)

  3. Support Staff 3 Posted by Stray on 04 Nov, 2011 11:53 AM

    Stray's Avatar

    Hi Will,

    I'm not sure it's possible to fix it generically - it's just a reality that the mapping can't be unmapped by the map until the command has executed. If you squeeze another mapping in to that process then the mapping may have to be overwritten.

    The purpose of the warning is only to 'warn' you. In most cases, overwriting a mapping means that you made a mistake. In this case it doesn't - so, the warning is still sensible in my view.

    The child injector is the one used to instantiate the Command, so if you just inject IInjector then the one injected will be the child injector of the SCM - so you can do that part easily.



  4. Ondina D.F. closed this discussion on 08 Dec, 2011 12:23 PM.

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

Keyboard shortcuts


? 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