From patchwork Wed Sep 18 06:17:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 1163758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Y8vV1BTSz9sCJ for ; Wed, 18 Sep 2019 16:19:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="dJBoE8Dk"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46Y8vT4KNszF3Xb for ; Wed, 18 Sep 2019 16:19:17 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=axtens.net (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=dja@axtens.net; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b="dJBoE8Dk"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46Y8tt6k7PzF1Qy for ; Wed, 18 Sep 2019 16:18:46 +1000 (AEST) Received: by mail-pf1-x441.google.com with SMTP id y5so3665706pfo.4 for ; Tue, 17 Sep 2019 23:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q5trydgVI87zPDO24nwaA8pb1styFOfbn9am51fdXpE=; b=dJBoE8Dk1I1Ep/CHUYvwgyOTfME0bO3Nk/DyG2U83wh3umLhMxY0WXKiKC6c4CvbXC uFJhzTaHvDrR+U6eTQpsnpQRL5cUahNUPVx6UDIuLH3Lg/4AhhBuYIpNenWtpvrc5vGW d1HwziPcO+94Z1h12PLoXbrA32AU82gOpJ/as= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q5trydgVI87zPDO24nwaA8pb1styFOfbn9am51fdXpE=; b=d1b7OVfX6Rr60s2UBPyOJEQqKrbExx9sY0PSXFkfdcnubN7gxvdIsBHrU8BPb0tZmX 6iD7j1b4pbC7vWlEnM43SLX5nNMkhMGJAeoNpL+s90zy9mzn3LEytsKab1s0o28FfQsm +3Wy5/Dm0NZBtF+RzJEb9GuKAXrhCCREYuEAtYIRBlCdmDJ808gN98x5KYLggEiBniYn jSRrNN1eGyDlfRii96MwWLqdN87EOD8YKmQ4lIH/GZpHVSF1lON4GJeanD0YQ6x5/aAj 4MpEz1NsoeroCYNdhPJybqXnXa4jSKbfoNhHNUztu8Ag2wuGlcWzHjJ1q4gNBFqKjL4G 3LNA== X-Gm-Message-State: APjAAAVmCUpVIgIVZ9w8XauSuCJUpjG6IHRI7ZnJrS7dAGBeEgN3ziGS DVivOzWMBiZ0ReNemwcMOy/kgNOkid4= X-Google-Smtp-Source: APXvYqwZ16eKciFExcGbBNSGYt/GlV6jEPXi4QW4m5qAfzxWO7SjZd0B1necG/U631NnrOlpT41cpA== X-Received: by 2002:a17:90a:fa01:: with SMTP id cm1mr1213365pjb.140.1568787523762; Tue, 17 Sep 2019 23:18:43 -0700 (PDT) Received: from localhost (ppp167-251-205.static.internode.on.net. [59.167.251.205]) by smtp.gmail.com with ESMTPSA id n9sm4494516pgf.64.2019.09.17.23.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 23:18:43 -0700 (PDT) From: Daniel Axtens To: patchwork@lists.ozlabs.org Subject: [PATCH 3/6] parsearchive, mail: use repr() to get a human readable exception Date: Wed, 18 Sep 2019 16:17:28 +1000 Message-Id: <20190918061731.19142-4-dja@axtens.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190918061731.19142-1-dja@axtens.net> References: <20190918061731.19142-1-dja@axtens.net> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 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 Reviewed-by: Stephen Finucane --- patchwork/management/commands/parsearchive.py | 2 +- patchwork/management/commands/parsemail.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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)