Repository: mandiant/capa
File: capa/main.py (Python)

Code before:
            )
            logger.debug("-" * 80)

            sigs_path = get_default_root() / "sigs"

            if not sigs_path.exists():
                logger.error(
                    "Using default signature path, but it doesn't exist. "  # noqa: G003 [logging statement uses +]
                    + "Please install the signatures first: "
                    + "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library."
                )
                raise IOError(f"signatures path {sigs_path} does not exist or cannot be accessed")
        else:
            sigs_path = Path(args.signatures)
            logger.debug("using signatures path: %s", sigs_path)

        args.signatures = sigs_path


def simple_message_exception_handler(
    exctype: Union[type[BaseException], Type[BaseException]],
    value: BaseException,
    traceback: TracebackType,
):
    """
    if not in debug mode, prints helpful message on unhandled exceptions

    args:
      # TODO(aaronatp): Once capa drops support for Python 3.8, move this to the type annotation in the function parameters
      exctype (type[BaseException]): exception class
    """

    print(
        f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) "
        + "to see the stack trace. Please also report your issue on the capa GitHub page so we "
        + "can improve the code! (https://github.com/mandiant/capa/issues)"
    )


def main(argv: Optional[List[str]] = None):
    if sys.version_info < (3, 8):
        raise UnsupportedRuntimeError("This version of capa can only be used with Python 3.8+")

    if argv is None:
        argv = sys.argv[1:]

    desc = "The FLARE team's open-source tool to identify capabilities in executable files."
    epilog = textwrap.dedent(
        """
        By default, capa uses a default set of embedded rules.
        You can see the rule set here:

Review comment (bug):
```suggestion
    prints friendly message on unhandled exceptions to regular users, debug mode shows regular stack trace
```

Code after:
            logger.debug("-" * 80)

            sigs_path = get_default_root() / "sigs"

            if not sigs_path.exists():
                logger.error(
                    "Using default signature path, but it doesn't exist. "  # noqa: G003 [logging statement uses +]
                    + "Please install the signatures first: "
                    + "https://github.com/mandiant/capa/blob/master/doc/installation.md#method-2-using-capa-as-a-python-library."
                )
                raise IOError(f"signatures path {sigs_path} does not exist or cannot be accessed")
        else:
            sigs_path = Path(args.signatures)
            logger.debug("using signatures path: %s", sigs_path)

        args.signatures = sigs_path


def simple_message_exception_handler(exctype, value: BaseException, traceback: TracebackType):
    """
    prints friendly message on unexpected exceptions to regular users (debug mode shows regular stack trace)

    args:
      # TODO(aaronatp): Once capa drops support for Python 3.8, move the exctype type annotation to
      # the function parameters and remove the "# type: ignore[assignment]" from the relevant place
      # in the main function, see (https://github.com/mandiant/capa/issues/1896)
      exctype (type[BaseException]): exception class
    """

    if exctype is KeyboardInterrupt:
        print("KeyboardInterrupt detected, program terminated")
    else:
        print(
            f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) "
            + "to see the stack trace. Please also report your issue on the capa GitHub page so we "
            + "can improve the code! (https://github.com/mandiant/capa/issues)"
        )


def main(argv: Optional[List[str]] = None):
    if sys.version_info < (3, 8):
        raise UnsupportedRuntimeError("This version of capa can only be used with Python 3.8+")

    if argv is None:
        argv = sys.argv[1:]

    desc = "The FLARE team's open-source tool to identify capabilities in executable files."
    epilog = textwrap.dedent(
        """
        By default, capa uses a default set of embedded rules.
        You can see the rule set here: