diff mbox series

xen/misra: xen-analysis.py: fix return error on PhaseExceptions

Message ID 20230426104605.3447049-1-luca.fancellu@arm.com (mailing list archive)
State Superseded
Headers show
Series xen/misra: xen-analysis.py: fix return error on PhaseExceptions | expand

Commit Message

Luca Fancellu April 26, 2023, 10:46 a.m. UTC
Currently the script return code is 0 even if an exception is
found, because the return code is written only if the exception
object has the errorcode member.

Fix the issue returning the errorcode member in case it exists,
otherwise use a generic value different from 0.

Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 xen/scripts/xen-analysis.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Andrew Cooper April 26, 2023, 2:08 p.m. UTC | #1
On 26/04/2023 11:46 am, Luca Fancellu wrote:
> Currently the script return code is 0 even if an exception is
> found, because the return code is written only if the exception
> object has the errorcode member.
>
> Fix the issue returning the errorcode member in case it exists,
> otherwise use a generic value different from 0.
>
> Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
>  xen/scripts/xen-analysis.py | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/xen/scripts/xen-analysis.py b/xen/scripts/xen-analysis.py
> index 8e50c27cd898..7185c5a06d2c 100755
> --- a/xen/scripts/xen-analysis.py
> +++ b/xen/scripts/xen-analysis.py
> @@ -26,8 +26,7 @@ def main(argv):
>              cppcheck_analysis.generate_cppcheck_report()
>      except PhaseExceptions as e:
>          print("ERROR: {}".format(e))
> -        if hasattr(e, "errorcode"):
> -            ret_code = e.errorcode
> +        ret_code = e.errorcode if hasattr(e, "errorcode") else 1

ret_code = getattr(e, "errorcode", 1)

is rather more succinct, and pythonic.

~Andrew
Luca Fancellu April 26, 2023, 2:37 p.m. UTC | #2
> On 26 Apr 2023, at 15:08, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> On 26/04/2023 11:46 am, Luca Fancellu wrote:
>> Currently the script return code is 0 even if an exception is
>> found, because the return code is written only if the exception
>> object has the errorcode member.
>> 
>> Fix the issue returning the errorcode member in case it exists,
>> otherwise use a generic value different from 0.
>> 
>> Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")
>> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
>> ---
>> xen/scripts/xen-analysis.py | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>> 
>> diff --git a/xen/scripts/xen-analysis.py b/xen/scripts/xen-analysis.py
>> index 8e50c27cd898..7185c5a06d2c 100755
>> --- a/xen/scripts/xen-analysis.py
>> +++ b/xen/scripts/xen-analysis.py
>> @@ -26,8 +26,7 @@ def main(argv):
>>             cppcheck_analysis.generate_cppcheck_report()
>>     except PhaseExceptions as e:
>>         print("ERROR: {}".format(e))
>> -        if hasattr(e, "errorcode"):
>> -            ret_code = e.errorcode
>> +        ret_code = e.errorcode if hasattr(e, "errorcode") else 1
> 
> ret_code = getattr(e, "errorcode", 1)
> 
> is rather more succinct, and pythonic.

Yes it looks better, I’ll update the patch

> 
> ~Andrew
diff mbox series

Patch

diff --git a/xen/scripts/xen-analysis.py b/xen/scripts/xen-analysis.py
index 8e50c27cd898..7185c5a06d2c 100755
--- a/xen/scripts/xen-analysis.py
+++ b/xen/scripts/xen-analysis.py
@@ -26,8 +26,7 @@  def main(argv):
             cppcheck_analysis.generate_cppcheck_report()
     except PhaseExceptions as e:
         print("ERROR: {}".format(e))
-        if hasattr(e, "errorcode"):
-            ret_code = e.errorcode
+        ret_code = e.errorcode if hasattr(e, "errorcode") else 1
     finally:
         if settings.step_clean_analysis:
             cppcheck_analysis.clean_analysis_artifacts()