From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFCC9C433F5 for ; Thu, 4 Nov 2021 18:53:18 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21D3061157 for ; Thu, 4 Nov 2021 18:53:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 21D3061157 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CCD28836BC; Thu, 4 Nov 2021 19:53:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="E6XaFeSF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DEFBF836BE; Thu, 4 Nov 2021 19:53:09 +0100 (CET) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4FCD6836BB for ; Thu, 4 Nov 2021 19:53:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heiko.thiery@gmail.com Received: by mail-wr1-x434.google.com with SMTP id i5so10154399wrb.2 for ; Thu, 04 Nov 2021 11:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=azKIN9Lewfa6wPEc2DUsfyvEEWQ+FPwhkdTGZuaTnM4=; b=E6XaFeSFLgdmvVT5HHOiT5TXIfSw0GYGQz5cAqEoNuMwsd+gBNeJn8875MESrjZQ07 zdj7XZQDvoXL2A3jzTGORnLfqR0yi3kU2n+bqdqHbrr8J1PDwwJ384z4jlP5/ks/Kdum 7W1yXsQpVpVsKqw1H2vpl7Nnd5sxxhIq73blGVo9kP/4WUJrS90qcDhgyx6gXuNh0aCz 5nuv67qMedltelCYW4x7xYNLuFYHVqnfrKndQKruCuCefz0Z1hQI4joZwv7Am32IvrNn Ad2plIp10ADr0h8Tp6TwGJbrhqhQPMFrfgXADw4Z45kbgRnFwGEelKMz0yI/gP8LJeVp 5DVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=azKIN9Lewfa6wPEc2DUsfyvEEWQ+FPwhkdTGZuaTnM4=; b=xfP2LM07U7Sf+AM2ZRED6GK8hfuigtcwSsSt/kPmQrz4eDrt/CYn51HPPA3XHSd184 3NhUBv2B3acEgPsUplnfSaucDhM5M5wXsbOjPu5ylV8l0HqsgEhzHNgIox09xirRep62 8JZAwfRiM1zeqH/QpYe/DkM1cRNPiI+Gy2xA8Qu0lCgb20eZD0vHt2mszTD8XJ62eJEQ PHFduH1XytLZmD6UdKawfwWDZjDba+SCgRD0gqce4gwcjAr5QvYqstua3eaqF5FHPbaQ mLCvqhxm1/RT+P6xoJ3Q4c3bsefWhktXT8198MwSXgM8BjPsorPIcq6ZJL122zMglILt snUA== X-Gm-Message-State: AOAM530deqxAS/41jBtk29MywIYtkahOe5YfUJyEaENVE+E8eQZCIJbk oqZu+5FeN2KheOZOza6cFJb1thERbIM= X-Google-Smtp-Source: ABdhPJyCA2FGgW+eO4K2jjOQs2ErNFp8pVgQzZxptVe1Ai+hPg1mc9l/7DiXX3CQVyEMYX8L+O/P5A== X-Received: by 2002:adf:ef52:: with SMTP id c18mr46926852wrp.162.1636051984739; Thu, 04 Nov 2021 11:53:04 -0700 (PDT) Received: from hthiery.fritz.box ([2a02:810c:8d40:ec0:8e16:45ff:fe22:ad85]) by smtp.gmail.com with ESMTPSA id l15sm1779829wme.47.2021.11.04.11.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 11:53:04 -0700 (PDT) From: Heiko Thiery To: u-boot@lists.denx.de Cc: Stefano Babic , Fabio Estevam , Michael Walle , Simon Glass , Heiko Thiery Subject: [RFC 1/2] patman: introduce RunException Date: Thu, 4 Nov 2021 19:52:32 +0100 Message-Id: <20211104185231.2927-2-heiko.thiery@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211104185231.2927-1-heiko.thiery@gmail.com> References: <20211104185231.2927-1-heiko.thiery@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The RunException will be throws when the a command's return_code is not equal zero. With this an external caller can catch that and has access to the command/args, the result code, the stdout and stderr output. Signed-off-by: Heiko Thiery --- tools/patman/tools.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 710f1fdcd3..ca1c9114ab 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -313,6 +313,18 @@ def GetTargetCompileTool(name, cross_compile=None): target_name = name return target_name, extra_args +class RunException(Exception): + """Exception that is thrown when the command fails""" + def __init__(self, args, result): + self.args = args + self.stdout = result.stdout.strip() + self.stderr = result.stderr.strip() + self.return_code = result.return_code + + def __str__(self): + return ("Error %d running '%s': %s" % + (self.return_code,' '.join(self.args), self.stderr)) + def Run(name, *args, **kwargs): """Run a tool with some arguments @@ -349,9 +361,7 @@ def Run(name, *args, **kwargs): result = command.RunPipe([all_args], capture=True, capture_stderr=True, env=env, raise_on_error=False, binary=binary) if result.return_code: - raise Exception("Error %d running '%s': %s" % - (result.return_code,' '.join(all_args), - result.stderr)) + raise RunException(all_args, result) return result.stdout except: if env and not PathHasFile(env['PATH'], name): -- 2.30.2