Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error when a state includes salt['foo.bar'] without () #3029

Closed
SEJeff opened this issue Dec 27, 2012 · 3 comments
Closed

Better error when a state includes salt['foo.bar'] without () #3029

SEJeff opened this issue Dec 27, 2012 · 3 comments
Labels
Feature new functionality including changes to functionality and code refactors, etc. stale
Milestone

Comments

@SEJeff
Copy link
Contributor

SEJeff commented Dec 27, 2012

Example naiive state:

{% if 'jeff' in salt['user.list_users'] %}
/tmp/jeff-is-here.txt:
  file.touch
{% endif %}

Completely unobvious (to a non-developer) error when running state.highstate:

local:
    Data failed to compile:
----------
    Rendering SLS dev.salt failed, render error:
Traceback (most recent call last):
  File "/home/jeff/git/salt/salt/utils/templates.py", line 54, in render_tmpl
    output = render_str(tmplstr, context, tmplpath)
  File "/home/jeff/git/salt/salt/utils/templates.py", line 94, in render_jinja_tmpl
    output = jinja_env.from_string(tmplstr).render(**context)
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "<template>", line 25, in top-level template code
TypeError: argument of type 'function' is not iterable

I am aware that the correct state is the same as above but the first line should look like:

{% if 'jeff' in salt['user.list_users']() %}

However, this is a simple mistake and we should try (if possible) to present a more obvious and friendly error message. This was found while testing out #3028

@thatch45
Copy link
Member

Yes, this is tricky, since this is going down the path of catching a bunch of specific templating errors. but catching the common ones would be a good idea

@SEJeff
Copy link
Contributor Author

SEJeff commented Mar 8, 2013

Perhaps there is somewhere in the code you can do something like if callable(fun) error: You need to call the function with parenthesis? I'm unsure if this would require subclassing the renderer or could be done elsewhere in the stack? Perhaps it could be done in templates.py? I want to believe this isn't that hard.

@rallytime rallytime added the Feature new functionality including changes to functionality and code refactors, etc. label Sep 30, 2014
@stale stale bot added the stale label Sep 5, 2017
@stale
Copy link

stale bot commented Sep 5, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot closed this as completed Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature new functionality including changes to functionality and code refactors, etc. stale
Projects
None yet
Development

No branches or pull requests

3 participants