Skip to content

Commit

Permalink
Print errors after resetting terminal from progress output
Browse files Browse the repository at this point in the history
  • Loading branch information
akenion committed Aug 31, 2023
1 parent 7a9d7ed commit 1bbe2f5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions wordfence/cli/scan/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def revert_progress_changes() -> None:
if screen_handler:
log.removeHandler(screen_handler)
restore_initial_handler()
reset_terminal()


class ScanCommand:
Expand Down Expand Up @@ -260,6 +261,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 @@ -288,13 +301,12 @@ 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 config.debug:
raise exception
else:
log.error(f'Error: {exception}')
print_error(f'Error: {exception}')
return 1
finally:
reset_terminal()

0 comments on commit 1bbe2f5

Please sign in to comment.