Skip to content

Commit e69a436

Browse files
authored
Merge pull request #218 from hroncok/issue211
Command not found will no longer traceback
2 parents 238196c + 4471e51 commit e69a436

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

jupyter_core/command.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ def main():
282282
parser.print_usage(file=sys.stderr)
283283
sys.exit("subcommand is required")
284284

285-
command = _jupyter_abspath(subcommand)
285+
try:
286+
command = _jupyter_abspath(subcommand)
287+
except Exception as e:
288+
sys.exit(e)
286289

287290
try:
288291
_execvp(command, sys.argv[1:])

jupyter_core/tests/test_command.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import sys
66
import sysconfig
7-
from subprocess import check_output, CalledProcessError
7+
from subprocess import check_output, PIPE, CalledProcessError
88
from unittest.mock import patch
99

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

2626

2727
def write_executable(path, source):
@@ -109,8 +109,10 @@ def test_help():
109109

110110

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

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

0 commit comments

Comments
 (0)