Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,11 @@ def do_run(self, arg):
if arg:
import shlex
argv0 = sys.argv[0:1]
sys.argv = shlex.split(arg)
try:
sys.argv = shlex.split(arg)
except ValueError as e:
self.error('Cannot run %s: %s' % (arg, e))
return
sys.argv[:0] = argv0
# this is caught in the main debugger loop
raise Restart
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,21 @@ def test_errors_in_command(self):
'(Pdb) ',
])

def test_issue34266(self):
'''do_run handles exceptions from parsing its arg'''
def check(bad_arg, msg):
commands = "\n".join([
f'run {bad_arg}',
'q',
])
stdout, _ = self.run_pdb_script('pass', commands + '\n')
self.assertEqual(stdout.splitlines()[1:], [
'-> pass',
f'(Pdb) *** Cannot run {bad_arg}: {msg}',
'(Pdb) ',
])
check('\\', 'No escaped character')
check('\"', 'No closing quotation')

def test_issue42384(self):
'''When running `python foo.py` sys.path[0] is an absolute path. `python -m pdb foo.py` should behave the same'''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle exceptions from parsing the arg of :mod:`pdb`'s run/restart command.