Skip to content

Commit

Permalink
Show error before showing the XML output.
Browse files Browse the repository at this point in the history
  • Loading branch information
rabsondev committed Jan 17, 2024
1 parent 7ca958f commit 1c9934b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
4 changes: 1 addition & 3 deletions agent/nmap_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def parse_output(xml_output: str) -> dict[str, Any]:
return parsed_xml
except xml.parsers.expat.ExpatError as parsing_error:
logger.error(
"Error parsing XML output: %s - Original Error: %s",
xml_output,
parsing_error,
"Error parsing XML output: %s - XML output: %s", parsing_error, xml_output
)
raise

Expand Down
2 changes: 0 additions & 2 deletions tests/nmap_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def testNmapWrapper_whenAllTopPortsUsed_returnCommand(
def testNmapWrapperParseOutput_whenXmlIsInvalid_catchesAndReraisesError() -> None:
"""Tests parsing invalid XML output scan results. Should catch the error and re-raise it."""
invalid_xml = (pathlib.Path(__file__).parent / "malformed_output.xml").read_text()

parsed_output = None

with pytest.raises(xml.parsers.expat.ExpatError):
Expand All @@ -139,7 +138,6 @@ def testNmapWrapperParseOutput_whenXmlIsValid_returnsParsedXml() -> None:
valid_xml = (
pathlib.Path(__file__).parent / "fake_output_with_down_host.xml"
).read_text()

parsed_output = nmap_wrapper.parse_output(valid_xml)

assert {
Expand Down

0 comments on commit 1c9934b

Please sign in to comment.