Skip to contentSkip to conversation

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

PATCH In review Luca Fancellu 2 participants 3 messages Apr 27, 2023 – Apr 28, 2023

lore
Share & tools
lore
#0 lore raw

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

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")
Change-Id I1b76b8fa4668bef49da3282339fca3052e3379cd

---
Changes from v1:
- use getattr() (Andrew)

---
 xen/scripts/xen-analysis.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/scripts/xen-analysis.py +1 -2
index 8e50c27cd898..5e8f2910cd72 100755
@@ -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()
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Luca Fancellu

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")
Quoted 1 line

Change-Id: I1b76b8fa4668bef49da3282339fca3052e3379cd

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

~Andrew

Quoted 21 lines

---
Changes from v1:
- use getattr() (Andrew)

---
 xen/scripts/xen-analysis.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/scripts/xen-analysis.py +1 -2
index 8e50c27cd898..5e8f2910cd72 100755
@@ -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 lore raw
Quoted 12 lines · Andrew Cooper
Quoted 7 lines · Luca Fancellu

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.

Quoted 8 lines
Quoted 2 lines
Fixes 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")
Quoted 1 line

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

Quoted 25 lines

~Andrew

Quoted 21 lines

---
Changes from v1:
- use getattr() (Andrew)
---
xen/scripts/xen-analysis.py | 3 +--

1 file changed, 1 insertion(+), 2 deletions(-)
xen/scripts/xen-analysis.py +1 -2
index 8e50c27cd898..5e8f2910cd72 100755
@@ -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()