{"action":"created","issue":{"url":"https://api.github.com/repos/malthe/chameleon/issues/129","repository_url":"https://api.github.com/repos/malthe/chameleon","labels_url":"https://api.github.com/repos/malthe/chameleon/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/malthe/chameleon/issues/129/comments","events_url":"https://api.github.com/repos/malthe/chameleon/issues/129/events","html_url":"https://github.com/malthe/chameleon/issues/129","id":7675230,"number":129,"title":"Use of exists: with erroneous code shows incorrect error in page template","user":{"login":"davidjb","id":1002811,"avatar_url":"https://avatars.githubusercontent.com/u/1002811?v=3","gravatar_id":"","url":"https://api.github.com/users/davidjb","html_url":"https://github.com/davidjb","followers_url":"https://api.github.com/users/davidjb/followers","following_url":"https://api.github.com/users/davidjb/following{/other_user}","gists_url":"https://api.github.com/users/davidjb/gists{/gist_id}","starred_url":"https://api.github.com/users/davidjb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidjb/subscriptions","organizations_url":"https://api.github.com/users/davidjb/orgs","repos_url":"https://api.github.com/users/davidjb/repos","events_url":"https://api.github.com/users/davidjb/events{/privacy}","received_events_url":"https://api.github.com/users/davidjb/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/malthe/chameleon/labels/core","name":"core","color":"02d7e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2012-10-18T01:57:20Z","updated_at":"2016-05-16T05:19:55Z","closed_at":null,"body":"By including this:\r\n\r\n```\r\n    <tal:block condition=\"exists:form\">\r\n    ...\r\n    </tal:block>\r\n```\r\nin a page template, it appears that any error that occurs on the page, such as by including this problematic snippet:\r\n\r\n    ${''.join([1,2,3])}\r\n\r\nproduces an incorrect traceback:\r\n\r\n```\r\nFile \"/home/david/.buildout/eggs/Chameleon-2.10-py2.7.egg/chameleon/template.py\", line 125, in __call__\r\n    return self.render(**kwargs)\r\n  File \"/home/david/.buildout/eggs/Chameleon-2.10-py2.7.egg/chameleon/zpt/template.py\", line 257, in render\r\n    return super(PageTemplate, self).render(**vars)\r\n  File \"/home/david/.buildout/eggs/Chameleon-2.10-py2.7.egg/chameleon/template.py\", line 190, in render\r\n    raise_with_traceback(exc, tb)\r\n  File \"/home/david/.buildout/eggs/Chameleon-2.10-py2.7.egg/chameleon/template.py\", line 172, in render\r\n    self._render(stream, econtext, rcontext)\r\n  File \"/tmp/tmpla4Pzm/profile_0a115cc2a1476969f981b6e5a3415492d4e5f193.py\", line 2656, in render\r\n    __macro.include(__stream, econtext.copy(), rcontext, __i18n_domain)\r\n  File \"/home/david/.buildout/eggs/Chameleon-2.10-py2.7.egg/chameleon/zpt/template.py\", line 261, in include\r\n    self._render(*args, **kwargs)\r\n  File \"/tmp/tmpNoXbaT/master_0dcd06fbeaf411b3407adc5bb4a14f8088378967.py\", line 726, in render\r\n    __slot_content(__stream, econtext.copy(), rcontext)\r\n  File \"/tmp/tmpla4Pzm/profile_0a115cc2a1476969f981b6e5a3415492d4e5f193.py\", line 641, in __fill_content\r\n    __content_140487793025840 = _lookup_attr('', 'join')([1, 2, 3, ])\r\nTypeError: form\r\n\r\n - Expression: \"\r\n      ${''.join([1,2,3])}\r\n      \"\r\n - Filename:   ... files/src/templates/profile.pt\r\n - Location:   (45:18)\r\n - Source:     </tal:block>\r\n                           ^\r\n - Expression: \"form\"\r\n - Filename:   ... files/src/templates/profile.pt\r\n - Location:   (43:35)\r\n - Source:     <tal:block condition=\"exists:form\">\r\n                                            ^^^^\r\n```\r\n\r\nPreviously the `Expression` was incorrect too (clearly referencing the exists: statement) but I can't seem to reproduce this yet.  As shown, the location, source and expression reference the `exists:`.\r\n\r\nAfter removing the `exists:` tal:block, the correct error is output:\r\n\r\n```\r\nTypeError: sequence item 0: expected string, int found\r\n\r\n - Expression: \"\r\n      ${''.join([1,2,3])}\r\n      \"\r\n - Filename:   ... files/src/templates/profile.pt\r\n - Location:   (42:12)\r\n - Source:     </div>\r\n                     ^\r\n```\r\n\r\nTested in Chameleon 2.10 and Python 2.7 (with Pyramid 1.4a2)."},"comment":{"url":"https://api.github.com/repos/malthe/chameleon/issues/comments/219350828","html_url":"https://github.com/malthe/chameleon/issues/129#issuecomment-219350828","issue_url":"https://api.github.com/repos/malthe/chameleon/issues/129","id":219350828,"user":{"login":"lieryan","id":1006989,"avatar_url":"https://avatars.githubusercontent.com/u/1006989?v=3","gravatar_id":"","url":"https://api.github.com/users/lieryan","html_url":"https://github.com/lieryan","followers_url":"https://api.github.com/users/lieryan/followers","following_url":"https://api.github.com/users/lieryan/following{/other_user}","gists_url":"https://api.github.com/users/lieryan/gists{/gist_id}","starred_url":"https://api.github.com/users/lieryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lieryan/subscriptions","organizations_url":"https://api.github.com/users/lieryan/orgs","repos_url":"https://api.github.com/users/lieryan/repos","events_url":"https://api.github.com/users/lieryan/events{/privacy}","received_events_url":"https://api.github.com/users/lieryan/received_events","type":"User","site_admin":false},"created_at":"2016-05-16T05:19:55Z","updated_at":"2016-05-16T05:19:55Z","body":"@malthe tested with Chameleon==2.24:\r\n\r\n```\r\nfrom chameleon import PageTemplate\r\nbody = '''\\\r\n<?xml version=\"1.0\"?>\r\n<root>\r\n    <one tal:condition=\"exists: var_does_not_exists\" />\r\n    <two tal:attributes=\"my_attr dict()['key-does-not-exist']\" />\r\n</root>\r\n'''\r\ntemplate = PageTemplate(body)\r\ntemplate()\r\n\r\n```\r\n\r\nActual Traceback:\r\n\r\n1. A weird amalgamation of error message: \"KeyError: var_does_not_exists\" (i.e. the correct error name but incorrect error message).\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 10, in <module>\r\n    template()\r\n  File \"/home/lieryan/.virtualenvs/tmp-f42733d8354a529/local/lib/python2.7/site-packages/chameleon/template.py\", line 124, in __call__\r\n    return self.render(**kwargs)\r\n  File \"/home/lieryan/.virtualenvs/tmp-f42733d8354a529/local/lib/python2.7/site-packages/chameleon/zpt/template.py\", line 261, in render\r\n    return super(PageTemplate, self).render(**vars)\r\n  File \"/home/lieryan/.virtualenvs/tmp-f42733d8354a529/local/lib/python2.7/site-packages/chameleon/template.py\", line 191, in render\r\n    raise_with_traceback(exc, tb)\r\n  File \"/home/lieryan/.virtualenvs/tmp-f42733d8354a529/local/lib/python2.7/site-packages/chameleon/template.py\", line 171, in render\r\n    self._render(stream, econtext, rcontext)\r\n  File \"a56b06593ae9e730d71f6e0ba777ae57.py\", line 133, in render\r\nKeyError: var_does_not_exists\r\n\r\n - Expression: \"dict()['key-does-not-exist']\"\r\n - Filename:   <string>\r\n - Location:   (line 4: col 33)\r\n - Expression: \" var_does_not_exists\"\r\n - Filename:   <string>\r\n - Location:   (line 3: col 31)\r\n - Arguments:  repeat: {...} (0)\r\n\r\n```\r\n\r\nExpected:\r\n\r\n1. the real error, which is \"KeyError: 'key-does-not-exists'\", should be in the traceback with the correct error message\r\n2. the AttributeError should be ignored completely instead of showing after the traceback, since it's within \"exists:\" clause."}}