Why does this snippet throw a cyclic dependency error?

Asked by Jeremy Cantrell

Here's the snippet in question. It seems simple enough. It actually expands to a UUID, but then it throws the attached error.

snippet uuid "Random UUID" w!
`!p import uuid; snip.rv = str(uuid.uuid4())`
endsnippet

An error occured. This is either a bug in UltiSnips or a bug in a
snippet definition. If you think this is a bug, please report it to
https://bugs.launchpad.net/ultisnips/+filebug.

Following is the full stack trace:
Traceback (most recent call last):
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 23, in wrapper
    return f(self, *args, **kwds)
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 569, in expand_or_jump
    rv = self._try_expand()
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 873, in _try_expand
    self._do_snippet(snippet, before, after)
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 847, in _do_snippet
    si = snippet.launch(text_before, self._visual_content, None, start, end)
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/__init__.py", line 417, in launch
    last_re = self._last_re, globals = self._globals)
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/text_objects/_snippet_instance.py", line 34, in __init__
    self.update_textobjects()
  File "/Users/jmcantrell/Code/dotfiles-vim/vim/bundle/ultisnips/plugin/UltiSnips/text_objects/_snippet_instance.py", line 74, in update_textobjects
    raise RuntimeError("Cyclic dependency in Snippet definition!")
RuntimeError: Cyclic dependency in Snippet definition!

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

This error is a bit misleading. I just replaced the message via

 The snippets content did not converge: Check for Cyclic dependencies or random strings in your snippet. You can use 'if not snip.c' to make sure to only expand random output once.

The problem is the uuid4 is random. UltiSnips evaluates textblocks till they do not change anymore, but your snippet will be different each time. use

if not snip.c:
   snip.rv = ...

Revision history for this message
Jeremy Cantrell (jmcantrell) said :
#2

Thanks for your help!

Revision history for this message
Jeremy Cantrell (jmcantrell) said :
#3

Thanks SirVer, that solved my question.