Skip to content

Commit

Permalink
Merge pull request #43 from wordfence/gh-37
Browse files Browse the repository at this point in the history
Print errors after resetting terminal from progress output
  • Loading branch information
akenion authored Aug 31, 2023
2 parents 6410716 + 1d27af6 commit 8f4ba84
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions wordfence/cli/scan/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def revert_progress_changes() -> None:
if screen_handler:
log.removeHandler(screen_handler)
restore_initial_handler()
reset_terminal()


class ScanCommand:
Expand Down Expand Up @@ -261,6 +262,18 @@ def handle_interrupt(signal_number: int, stack) -> None:
signal.signal(signal.SIGINT, handle_interrupt)


def print_error(message: str) -> None:
if sys.stderr is not None:
print(message, file=sys.stderr)
else:
print(message)


def reset_terminal_with_error(message: str) -> None:
reset_terminal()
print_error(message)


def display_version() -> None:
print(f"Wordfence CLI {__version__}")
jit_support_text = 'Yes' if pcre.HAS_JIT_SUPPORT else 'No'
Expand Down Expand Up @@ -289,18 +302,17 @@ def main(config) -> int:
command.execute()
return 0
except api.licensing.LicenseRequiredException:
log.error('A valid Wordfence CLI license is required')
reset_terminal_with_error('A valid Wordfence CLI license is required')
return 1
except BaseException as exception:
reset_terminal()
if isinstance(exception, ExceptionContainer):
if config.debug:
log.error(exception.trace)
print_error(exception.trace)
return 1
exception = exception.exception
if config.debug:
raise exception
else:
log.error(f'Error: {exception}')
print_error(f'Error: {exception}')
return 1
finally:
reset_terminal()

0 comments on commit 8f4ba84

Please sign in to comment.