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

user.pt doesn't render exceptions on Python 3 #2

Closed
jamadden opened this issue May 12, 2017 · 2 comments
Closed

user.pt doesn't render exceptions on Python 3 #2

jamadden opened this issue May 12, 2017 · 2 comments

Comments

@jamadden
Copy link
Member

Found this while porting zope.app.file.

It raises a UserError("some message") and expects that to get rendered. I verified that it does get caught by the publishing machinery and directed to the correct view. But that view is implemented in browser/user.pt like this:

  <ul>
    <li tal:repeat="part context" tal:content="part"
        i18n:translate="">Error message</li>
  </ul>

That is, it wants to iterate on the context, which is an exception.

In Python 2, iterating the exception does this:

(Pdb) pp list(iter(exception))
[u'The character set specified in the content type ($charset) does not match file content.']

But in Python 3, exceptions aren't iterable:

(Pdb) pp list(iter(exception))
*** TypeError: 'UserError' object is not iterable

And so the tal expression does nothing and the message doesn't make it back to the user.

Thoughts on the best way to fix this?

@jamadden
Copy link
Member Author

Changing the expression to this makes it work:

  <ul>
    <li tal:repeat="part context/args|context" tal:content="part"
        i18n:translate="">Error message</li>
  </ul>

@jamadden
Copy link
Member Author

The view is declared for zope.exceptions.interfaces.IUserError which says nothing about it being an Exception (and so having .args) or being iterable at all:

class IUserError(Interface):
    """User error exceptions
    """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant