Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print errors after resetting terminal from progress output #43

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()