Russell Merrick - 2022-10-18

I'm running cppcheck as a step in a CircleCI flow. Cppcheck is hitting some code that is causing a python exception. I'm not worried about the python assertion itself. The issue is that cppcheck still exites with code 0, implying that everything worked fine. How can cppcheck report a fail when it hits an exception? Here's one example for the output I'm seeing:

Building with "cppcheck"
Generating cppcheck-command
Running cppcheck
Bailing out from checking /root/project/test.c since there was an internal error: Failed to execute 'python3 /opt/conda/envs/test/share/Cppcheck/addons/misra.py --cli --rule-texts=/root/project/tools/cppcheck/misra-rules.txt -P /root/project/src /root/project/build/cppcheck_build_dir/test.a1.dump'. {"file": "/root/project/src/include/as6221_regs.h", "linenr": 66, "column": 30, "severity": "style", "message": "When an array with external linkage is declared, its size should be explicitly specified", "addon": "misra", "errorId": "c2012-8.11", "extra": "Advisory"}
Traceback (most recent call last):
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra.py", line 3492, in <module>
    main()
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra.py", line 3436, in main
    checker.parseDump(item)
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra.py", line 3267, in parseDump
    self.executeCheck(902, self.misra_9_2, cfg)
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra.py", line 3197, in executeCheck
    check_function(*args)
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra.py", line 1643, in misra_9_2
    misra_9.misra_9_x(self, data, 902)
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra_9.py", line 413, in misra_9_x
    parser.parseInitializer(ed, eq.astOperand2)
  File "/opt/conda/envs/test/share/Cppcheck/addons/misra_9.py", line 321, in parseInitializer
    if child.elementType != 'record' or self.token.valueType.type != 'record' or child.valueType.typeScope != self.token.valueType.typeScope:
AttributeError: 'NoneType' object has no attribute 'type'

Built target static-check
Built target cppcheck
CircleCI received exit code 0