LUA phrase_mapping error

I sometimes use this script, which is working fine in renoise 3.0:

https://gist.github.com/ryrun/2af8cb6fe7333d09675d

In renoise 3.1 i got this error:

*** std::logic_error: 'invalid phrase_mapping index '1'. no phrase_mapping's are available.'
*** stack traceback:
*** [C]: in function 'phrase_mapping'
*** PitchPhrases.lua:30: in main chunk

When i’m right, there is something wrong with line 30:

phrasemap = instr:phrase_mapping( phraseIdx )

Was this removed in renoise 3.1?

In 3.0 the phrases were always paired with a key mapping — they could not exist without it.

In 3.1 an instrument may now contain unmapped phrases that are selected by hand, by MIDI program changes, or with the new Zxx phrase trigger command.

It sounds like your instrument may not have any phrase mappings in the Keymap section, and so phrase_mapping(phraseIdx) is simply failing to return anything?

Ok, i was able to fix it withinsert_phrase_mapping_at. Thx.