Message ID | 20190918061731.19142-4-dja@axtens.net |
---|---|
State | Accepted |
Headers | show |
Series | A sketch of flattening the models with live migration | expand |
On Wed, 2019-09-18 at 16:17 +1000, Daniel Axtens wrote: > 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 "/home/patchwork/patchwork/patchwork/management/commands/parsearchive.py", line 90, in handle > obj = parse_mail(msg, options['list_id']) > File "/home/patchwork/patchwork/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 "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line > utility.execute() > File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) > File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv > self.execute(*args, **cmd_options) > File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute > output = self.handle(*args, **options) > File "/home/patchwork/patchwork/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> and applied (with some minor tweaks to the commit message).
diff --git a/patchwork/management/commands/parsearchive.py b/patchwork/management/commands/parsearchive.py index 37db2b0dc007..b7f1ea7313c2 100644 --- a/patchwork/management/commands/parsearchive.py +++ b/patchwork/management/commands/parsearchive.py @@ -97,7 +97,7 @@ class Command(BaseCommand): logger.warning('Duplicate mail for message ID %s', exc.msgid) except (ValueError, Exception) as exc: errors += 1 - logger.warning('Invalid mail: %s', exc.message) + logger.warning('Invalid mail: %s', repr(exc)) if verbosity < 3 and (i % 10) == 0: self.stdout.write('%06d/%06d\r' % (i, count), ending='') diff --git a/patchwork/management/commands/parsemail.py b/patchwork/management/commands/parsemail.py index b0871d211ad0..ea85e3aabb5c 100644 --- a/patchwork/management/commands/parsemail.py +++ b/patchwork/management/commands/parsemail.py @@ -70,6 +70,6 @@ class Command(base.BaseCommand): logger.warning('Duplicate mail for message ID %s', exc.msgid) except (ValueError, Exception) as exc: logger.exception('Error when parsing incoming email: %s', - exc.message, + repr(exc), extra={'mail': mail.as_string()}) sys.exit(1)
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 "/home/patchwork/patchwork/patchwork/management/commands/parsearchive.py", line 90, in handle obj = parse_mail(msg, options['list_id']) File "/home/patchwork/patchwork/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 "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/opt/pyenv/versions/3.7.4/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/home/patchwork/patchwork/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> --- patchwork/management/commands/parsearchive.py | 2 +- patchwork/management/commands/parsemail.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)