Bug Consult script + CCS that gets optimised out to nothing leads to "Invalid macro" abort

Using r25740, I have a CCS that goes like
Code:
[ default ]
special action
consult WHAM.ash

A few months ago this used to work fine, but now after returning from my pause, this breaks fights with an "Invalid Macro" error. After playing around with a few things, I think I've tracked it down to this:
In the GUI I only have the two pickpocketing-related special actions checked, but since I don't have that skill, it won't actually result in any special action taking place, unless I (or a script) happen to want to olfact something.

If by chance I happen to want to olfact something, this happens and things work fine:
Code:
stopping macrofication due to action: consult WHAM.ash
Generated macro:
sub mafiaround
endsub#mafiaround
sub mafiamp
    call mafiaround; use 347
    mark mafiampexit
endsub#mafiamp
#mafiaheader
if hasskill 19
    call mafiaround; skill 19
endif

Optimized macro:
#mafiaround
#mafiamp
#mafiaheader
if hasskill 19
    ; skill 19
endif
class net.sourceforge.kolmafia.request.FightRequest
Round 1: Crumbling Buttercookie executes a macro!
Connecting to fight.php...

Requesting: https://www.kingdomofloathing.com/fight.php?action=macro&macrotext=%0A%0A%0Aif+hasskill+19%0Askill+19%0Aendif%0A

If however no special action is necessary, it seems like the then empty "special action" macro is being optimised down to a bunch of newlines, which then seem to break KoL and cause an "Invalid Macro" message (with no further details):
Code:
stopping macrofication due to action: consult WHAM.ash
Generated macro:
sub mafiaround
endsub#mafiaround
sub mafiamp
    call mafiaround; use 347
    mark mafiampexit
endsub#mafiamp
#mafiaheader

Optimized macro:
#mafiaround
#mafiamp
#mafiaheader
class net.sourceforge.kolmafia.request.FightRequest
Round 1: Crumbling Buttercookie executes a macro!
Connecting to fight.php...

Requesting: https://www.kingdomofloathing.com/fight.php?action=macro&macrotext=%0A%0A%0A

Edit: I've realised the problem doesn't just apply to "special action" – if I add an entry for a specific monster with an explicit olfaction instruction before the consult script, the same thing happens when I encounter the monster once I've already olfacted it: The olfaction command is optimised into a bunch of newlines and bam, error.

I should also add that just using a consult script without any other further CCS instructions also works fine, since in that case it seems that Mafia doesn't attempt any combat macro generation at all.
 
Last edited:

Rinn

Developer
I think the macrofier needs to trim extra whitespace from the macro string, because currently it's checking if the length is not empty before sending it to kol, and since yours resolves to three newlines it's not empty but invalid.
 
I've managed to get a build going and found that bit of code you mention. It turns out that that particular check doesn't really help also because as far as I can tell, at the point of that check the macro still consists of
Code:
#mafiaround
#mafiamp
#mafiaheader
, so definitively wouldn't be considered empty, anyway.
The condensation down into a bunch of newlines only happens afterwards inside handleMacroAction. I've concocted a possible fix, though I've no idea whether it might be considered proper or not? I guess a should just put up a pull request?
 
Top