Skip to content

Commit 47744ff

Browse files
daxtensstephenfin
authored andcommitted
parsearchive, mail: use repr() to get a human readable exception
Currently if we have particular types of error in mail parsing in parsearchive or parsemail, we print exc.message, which doesn't always work: Traceback (most recent call last): File ".../patchwork/management/commands/parsearchive.py", line 90, in handle obj = parse_mail(msg, options['list_id']) File ".../patchwork/parser.py", line 961, in parse_mail raise ValueError("Missing 'Message-Id' header") ValueError: Missing 'Message-Id' header During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 11, in <module> execute_from_command_line(sys.argv) File ".../django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File ".../django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File ".../django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File ".../django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File ".../patchwork/management/commands/parsearchive.py", line 100, in handle logger.warning('Invalid mail: %s', exc.message) AttributeError: 'ValueError' object has no attribute 'message' repr(exc) will work. Use it. Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Stephen Finucane <stephen@that.guru> (cherry picked from commit 319b6f9)
1 parent 6a716c4 commit 47744ff

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

patchwork/management/commands/parsearchive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def handle(self, *args, **options):
9797
logger.warning('Duplicate mail for message ID %s', exc.msgid)
9898
except (ValueError, Exception) as exc:
9999
errors += 1
100-
logger.warning('Invalid mail: %s', exc.message)
100+
logger.warning('Invalid mail: %s', repr(exc))
101101

102102
if (i % 10) == 0:
103103
self.stdout.write('%06d/%06d\r' % (i, count), ending='')

patchwork/management/commands/parsemail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ def handle(self, *args, **options):
8484
logger.warning('Duplicate mail for message ID %s', exc.msgid)
8585
except (ValueError, Exception) as exc:
8686
logger.exception('Error when parsing incoming email: %s',
87-
exc.message,
87+
repr(exc),
8888
extra={'mail': mail.as_string()})
8989
sys.exit(1)

0 commit comments

Comments
 (0)