Skip to content

Error in email module exception handling #116705

Closed as duplicate
Closed as duplicate

Description

@naga0001

try:
value = value.decode(charset, 'surrogateescape')
except (LookupError, UnicodeEncodeError):

This is incorrect.
except (LookupError, UnicodeEncodeError):

Isn't this correct?
except (LookupError, UnicodeDecodeError):

Activity

  1. pochmann3 commented on Mar 13, 2024

    @pochmann3
    Contributor

    Why do you say it's incorrect? Because there's only a decode call? I can reproduce a UnicodeEncodeError with a decode:

    Traceback (most recent call last):
      File "/ATO/code", line 1, in <module>
        b''.decode('\udce2')
    UnicodeEncodeError: 'utf-8' codec can't encode character '\udce2' in position 0: surrogates not allowed
    

    Got that from the commit that added the UnicodeEncodeError catch. And the issue also showed a UnicodeEncodeError.

    I tried your change anyway, and it didn't make a test fail. Maybe a test should be added for that? (Maybe one was added but doesn't actually test it?)

  2. naga0001 commented on Mar 13, 2024

    @naga0001
    Author

    Sorry, I thought it was UnicodeDecodeError because it is simply decode.
    Was UnicodeDecodeError exception handling unnecessary for this process?

  3. pochmann3 commented on Mar 14, 2024

    @pochmann3
    Contributor

    I think the surrogateescape error handler indeed makes other exception handling unnecessary, but I'm no expert. You could also try asking on Discourse.

  4. picnixz commented on Jul 20, 2025

    @picnixz
    Member

    Closing in favor of #132794 as the latter has a better description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions