Skip to content

Commit 628a8a6

Browse files
authored
fix: halt if pdf selected but unavailable (#4354)
* Related to #4326 If pdf output is selected but isn't available, then cve-bin-tool tells you to install reportlab, but it was easy to miss that message as the scan continued and pushed it off the screen. This changes those messages to be errors instead of info messages to increase visibility and reflect the new behaviour where cve-bin-tool will exit without doing a scan if pdf is the only output mode selected. --------- Signed-off-by: Terri Oda <[email protected]>
1 parent f51f40f commit 628a8a6

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

cve_bin_tool/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
InsufficientArgs,
6464
InvalidExtensionError,
6565
MirrorError,
66+
PDFOutputUnavailable,
6667
excepthook,
6768
)
6869
from cve_bin_tool.input_engine import InputEngine, TriageData
@@ -893,11 +894,14 @@ def main(argv=None):
893894

894895
# Check for PDF support
895896
if "pdf" in output_formats and importlib.util.find_spec("reportlab") is None:
896-
LOGGER.info("PDF output not available.")
897-
LOGGER.info(
897+
LOGGER.error("PDF output not available.")
898+
LOGGER.error(
898899
"If you want to produce PDF output, please install reportlab using pip install reportlab"
899900
)
900901
output_formats.remove("pdf")
902+
if len(output_formats) < 1:
903+
# If there's no other formats selected, exit so people actually see the error
904+
return ERROR_CODES[PDFOutputUnavailable]
901905

902906
merged_reports = None
903907
if args["merge"]:

cve_bin_tool/error_handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class NetworkConnectionError(Exception):
145145
"""Raised when issue occurred with internet connection"""
146146

147147

148+
class PDFOutputUnavailable(Exception):
149+
"""Raised when reportlab is not installed and PDF output is unavailable"""
150+
151+
148152
class ErrorMode(Enum):
149153
Ignore = 0
150154
NoTrace = 1
@@ -246,4 +250,5 @@ def __exit__(self, exc_type, exc_val, exc_tb):
246250
InvalidExtensionError: 42,
247251
SigningError: 43,
248252
NetworkConnectionError: 44,
253+
PDFOutputUnavailable: 45,
249254
}

test/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def test_console_output_depending_reportlab_existence(self, caplog):
706706

707707
assert (
708708
"cve_bin_tool",
709-
logging.INFO,
709+
logging.ERROR,
710710
not_installed_msg,
711711
) in caplog.record_tuples
712712

0 commit comments

Comments
 (0)