Skip to content

Commit

Permalink
Merge pull request #218 from hroncok/issue211
Browse files Browse the repository at this point in the history
Command not found will no longer traceback
  • Loading branch information
kevin-bates authored Mar 7, 2021
2 parents 238196c + 4471e51 commit e69a436
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion jupyter_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ def main():
parser.print_usage(file=sys.stderr)
sys.exit("subcommand is required")

command = _jupyter_abspath(subcommand)
try:
command = _jupyter_abspath(subcommand)
except Exception as e:
sys.exit(e)

try:
_execvp(command, sys.argv[1:])
Expand Down
8 changes: 5 additions & 3 deletions jupyter_core/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import sys
import sysconfig
from subprocess import check_output, CalledProcessError
from subprocess import check_output, PIPE, CalledProcessError
from unittest.mock import patch

import pytest
Expand All @@ -21,7 +21,7 @@ def get_jupyter_output(cmd):
"""Get output of a jupyter command"""
if not isinstance(cmd, list):
cmd = [cmd]
return check_output([sys.executable, '-m', 'jupyter_core'] + cmd).decode('utf8').strip()
return check_output([sys.executable, '-m', 'jupyter_core'] + cmd, stderr=PIPE).decode('utf8').strip()


def write_executable(path, source):
Expand Down Expand Up @@ -109,8 +109,10 @@ def test_help():


def test_subcommand_not_found():
with pytest.raises(CalledProcessError):
with pytest.raises(CalledProcessError) as excinfo:
get_jupyter_output('nonexistant-subcommand')
stderr = excinfo.value.stderr.decode('utf8')
assert stderr == 'Jupyter command `jupyter-nonexistant-subcommand` not found.' + os.linesep

@patch.object(sys, 'argv', [__file__] + sys.argv[1:])
def test_subcommand_list(tmpdir):
Expand Down

0 comments on commit e69a436

Please sign in to comment.