Skip to content

Commit c9e1ae9

Browse files
Add exception handler when loading gnatcov Build targets
We still want to load the build targets (and the plugin) if gnatcov's help message contains non-escapable characters for XML. This can happen when enabling some gnatcov traces that are printed in stdout. For eng/ide/gnatstudio#297
1 parent c252591 commit c9e1ae9

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

share/support/ui/gnatcov.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,29 @@ def setup(self):
565565
# showing/hiding them appropriately. Also fill the custom targets.
566566
process = GPS.Process(["gnatcov", "--help"])
567567
help_msg = process.get_result()
568-
GPS.parse_xml(
569-
list_to_xml(self.BUILD_TARGET_MODELS).format(
570-
help=xml.sax.saxutils.escape(help_msg)
568+
569+
# Load the gnatcov's build targets, with the retrieved help message.
570+
# If an exception happens while loading the XML, try to load the build
571+
# targets again without the help message this time: the help message
572+
# should contain XML-escapable characters normally but we don't want
573+
# to avoid loading the plugin if it's not the case.
574+
try:
575+
GPS.parse_xml(
576+
list_to_xml(self.BUILD_TARGET_MODELS).format(
577+
help=xml.sax.saxutils.escape(help_msg)
578+
)
571579
)
572-
)
580+
except Exception as e:
581+
GPS.Logger("GNATCOVERAGE").log("Exception while loading XML: %s" % str(e))
582+
GPS.Logger("GNATCOVERAGE").log("GNATcov's help message: %s" % help_msg)
583+
GPS.Logger("GNATCOVERAGE").log(
584+
"Trying to reload the XML without gnatcov's help message..."
585+
)
586+
GPS.parse_xml(list_to_xml(self.BUILD_TARGET_MODELS))
587+
GPS.Logger("GNATCOVERAGE").log(
588+
"XML has been successfully loaded"
589+
)
590+
573591
self.update_worflow_build_targets()
574592

575593
# Try to retrieve a prebuilt GNATcov runtime from the history

0 commit comments

Comments
 (0)