[PATCH v2] xen/misra: xen-analysis.py: fix return error on PhaseExceptions

Luca Fancellu posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230427132559.14712-1-luca.fancellu@arm.com
xen/scripts/xen-analysis.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH v2] xen/misra: xen-analysis.py: fix return error on PhaseExceptions
Posted by Luca Fancellu 1 year ago
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>
Change-Id: I1b76b8fa4668bef49da3282339fca3052e3379cd
---
Changes from v1:
 - use getattr() (Andrew)
---
 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..5e8f2910cd72 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 = getattr(e, "errorcode", 1)
     finally:
         if settings.step_clean_analysis:
             cppcheck_analysis.clean_analysis_artifacts()
-- 
2.34.1
Re: [PATCH v2] xen/misra: xen-analysis.py: fix return error on PhaseExceptions
Posted by Andrew Cooper 1 year ago
On 27/04/2023 2:25 pm, 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>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

> Change-Id: I1b76b8fa4668bef49da3282339fca3052e3379cd

although this doesn't look like it should be here.  I've stripped it

~Andrew

> ---
> Changes from v1:
>  - use getattr() (Andrew)
> ---
>  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..5e8f2910cd72 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 = getattr(e, "errorcode", 1)
>      finally:
>          if settings.step_clean_analysis:
>              cppcheck_analysis.clean_analysis_artifacts()


Re: [PATCH v2] xen/misra: xen-analysis.py: fix return error on PhaseExceptions
Posted by Luca Fancellu 1 year ago

> On 27 Apr 2023, at 21:07, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> On 27/04/2023 2:25 pm, 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>
> 
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> 
>> Change-Id: I1b76b8fa4668bef49da3282339fca3052e3379cd
> 
> although this doesn't look like it should be here.  I've stripped it

My bad! I forgot to remove it before sending. Thanks

> 
> ~Andrew
> 
>> ---
>> Changes from v1:
>> - use getattr() (Andrew)
>> ---
>> 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..5e8f2910cd72 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 = getattr(e, "errorcode", 1)
>>     finally:
>>         if settings.step_clean_analysis:
>>             cppcheck_analysis.clean_analysis_artifacts()
>