Skip to content

Commit

Permalink
fix: halt if pdf selected but unavailable (#4354)
Browse files Browse the repository at this point in the history
* 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 <terri.oda@intel.com>
  • Loading branch information
terriko authored Aug 20, 2024
1 parent f51f40f commit 628a8a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
InsufficientArgs,
InvalidExtensionError,
MirrorError,
PDFOutputUnavailable,
excepthook,
)
from cve_bin_tool.input_engine import InputEngine, TriageData
Expand Down Expand Up @@ -893,11 +894,14 @@ def main(argv=None):

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

merged_reports = None
if args["merge"]:
Expand Down
5 changes: 5 additions & 0 deletions cve_bin_tool/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class NetworkConnectionError(Exception):
"""Raised when issue occurred with internet connection"""


class PDFOutputUnavailable(Exception):
"""Raised when reportlab is not installed and PDF output is unavailable"""


class ErrorMode(Enum):
Ignore = 0
NoTrace = 1
Expand Down Expand Up @@ -246,4 +250,5 @@ def __exit__(self, exc_type, exc_val, exc_tb):
InvalidExtensionError: 42,
SigningError: 43,
NetworkConnectionError: 44,
PDFOutputUnavailable: 45,
}
2 changes: 1 addition & 1 deletion test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def test_console_output_depending_reportlab_existence(self, caplog):

assert (
"cve_bin_tool",
logging.INFO,
logging.ERROR,
not_installed_msg,
) in caplog.record_tuples

Expand Down

0 comments on commit 628a8a6

Please sign in to comment.