Skip to content

Commit

Permalink
Improve error reporting to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Sep 1, 2020
1 parent 08c44b5 commit 415997c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
27 changes: 15 additions & 12 deletions px/px.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,23 @@ def install(argv):

# This is the setup.py entry point
def main():
argv = list(sys.argv)

loglevel = logging.ERROR
while '--debug' in argv:
argv.remove('--debug')
loglevel = logging.DEBUG

stringIO = six.StringIO()
configureLogging(loglevel, stringIO)

try:
_main(sys.argv)
_main(argv)
except Exception:
handleLogMessages(traceback.format_exc())
LOG = logging.getLogger(__name__)
LOG.exception("Uncaught Exception")

handleLogMessages(stringIO.getvalue())


def configureLogging(loglevel, stringIO):
Expand Down Expand Up @@ -124,11 +137,6 @@ def handleLogMessages(messages):


def _main(argv):
loglevel = logging.ERROR
while '--debug' in argv:
argv.remove('--debug')
loglevel = logging.DEBUG

if len(argv) == 1 and os.path.basename(argv[0]).endswith("top"):
argv.append("--top")

Expand All @@ -147,14 +155,10 @@ def _main(argv):
install(argv)
return

stringIO = six.StringIO()
configureLogging(loglevel, stringIO)

if arg == '--top':
# Pulling px_top in on demand like this improves test result caching
from . import px_top
px_top.top()
handleLogMessages(stringIO.getvalue())
return

if arg == '--help':
Expand All @@ -175,7 +179,6 @@ def _main(argv):
try:
pid = int(arg)
px_processinfo.print_pid_info(sys.stdout.fileno(), pid)
handleLogMessages(stringIO.getvalue())
return
except ValueError:
# It's a search filter and not a PID, keep moving
Expand Down
1 change: 0 additions & 1 deletion px/px_loginhistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import dateutil.tz

if False:
import logging # NOQA
from typing import Set, Optional # NOQA

LOG = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion px/px_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

if False:
# For mypy PEP-484 static typing validation
import logging # NOQA
from . import px_process # NOQA
from typing import List # NOQA
from typing import Optional # NOQA
Expand Down
1 change: 0 additions & 1 deletion px/px_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

if False:
# For mypy PEP-484 static typing validation
import logging # NOQA
from typing import List # NOQA
from typing import Dict # NOQA
from typing import Union # NOQA
Expand Down

0 comments on commit 415997c

Please sign in to comment.