lcov-to-cobertura-xml icon indicating copy to clipboard operation
lcov-to-cobertura-xml copied to clipboard

duplicate matches in `--excludes` will lead to errors

Open dothebart opened this issue 6 months ago • 0 comments

It seems if more that one --excludes wants to match on a single item one gets uncaught exceptions. Changing it to an error message instead:

diff --git a/lcov_cobertura/lcov_cobertura.py b/lcov_cobertura/lcov_cobertura.py
index 379e405..3faf7a9 100755
--- a/lcov_cobertura/lcov_cobertura.py
+++ b/lcov_cobertura/lcov_cobertura.py
@@ -217,7 +217,10 @@ class LcovCobertura():
         excluded = [x for x in coverage_data['packages'] for e in self.excludes
                     if re.match(e, x)]
         for package in excluded:
-            del coverage_data['packages'][package]
+            try:
+                del coverage_data['packages'][package]
+            except KeyError as ex:
+                print(f"skipping filter for {package} - not found; duplicate exclude pattern match?")
 
         # Compute line coverage rates
         for package_data in list(coverage_data['packages'].values()):
@@ -425,8 +428,8 @@ def main(argv=None):
             cobertura_xml = lcov_cobertura.convert()
         with open(options.output, mode='wt') as output_file:
             output_file.write(cobertura_xml)
-    except IOError:
-        sys.stderr.write("Unable to convert %s to Cobertura XML" % args[1])
+    except IOError as ex:
+        sys.stderr.write("Unable to convert %s to Cobertura XML %s" % (args[1], ex))
 
 
 if __name__ == '__main__':

dothebart avatar Feb 20 '24 15:02 dothebart