mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Handle KeyError while getting or setting variables (#413)
This commit is contained in:
parent
0b42993169
commit
8a8ba9f449
2 changed files with 50 additions and 2 deletions
|
|
@ -1292,7 +1292,11 @@ class VSCodeMessageProcessor(ipcjson.SocketIO, ipcjson.IpcChannel):
|
|||
vsc_var = int(args['variablesReference'])
|
||||
fmt = args.get('format', {})
|
||||
|
||||
pyd_var = self.var_map.to_pydevd(vsc_var)
|
||||
try:
|
||||
pyd_var = self.var_map.to_pydevd(vsc_var)
|
||||
except KeyError:
|
||||
self.send_error_response(request)
|
||||
return
|
||||
|
||||
if len(pyd_var) == 3:
|
||||
cmd = pydevd_comm.CMD_GET_FRAME
|
||||
|
|
@ -1383,7 +1387,11 @@ class VSCodeMessageProcessor(ipcjson.SocketIO, ipcjson.IpcChannel):
|
|||
"""Handles DAP SetVariableRequest."""
|
||||
|
||||
vsc_var = int(args['variablesReference'])
|
||||
pyd_var = self.var_map.to_pydevd(vsc_var)
|
||||
try:
|
||||
pyd_var = self.var_map.to_pydevd(vsc_var)
|
||||
except KeyError:
|
||||
self.send_error_response(request)
|
||||
return
|
||||
|
||||
var_name = args['name']
|
||||
var_value = args['value']
|
||||
|
|
|
|||
|
|
@ -449,6 +449,25 @@ class VariablesTests(NormalRequestTest, unittest.TestCase):
|
|||
self.expected_pydevd_request('{}\t2\tFRAME'.format(thread.id)),
|
||||
])
|
||||
|
||||
def test_invalid_var_ref(self):
|
||||
with self.launched():
|
||||
with self.hidden():
|
||||
_, thread = self.pause('t', *[
|
||||
# (pfid, func, file, line)
|
||||
(2, 'spam', 'abc.py', 10), # VSC frame ID 1
|
||||
(5, 'eggs', 'xyz.py', 2), # VSC frame ID 2
|
||||
])
|
||||
self.send_request(
|
||||
# should NOT match variable or frame ID
|
||||
variablesReference=12345,
|
||||
)
|
||||
received = self.vsc.received
|
||||
|
||||
self.assert_vsc_received(received, [
|
||||
self.expected_failure(''),
|
||||
# no events
|
||||
])
|
||||
|
||||
def test_container(self):
|
||||
self.PYDEVD_CMD = CMD_GET_FRAME
|
||||
with self.launched():
|
||||
|
|
@ -570,6 +589,27 @@ class SetVariableTests(NormalRequestTest, unittest.TestCase):
|
|||
'{}\t2\tLOCAL\tspam\t1'.format(thread.id)),
|
||||
])
|
||||
|
||||
def test_invalid_var_ref(self):
|
||||
with self.launched():
|
||||
with self.hidden():
|
||||
_, thread = self.pause('t', *[
|
||||
# (pfid, func, file, line)
|
||||
(2, 'spam', 'abc.py', 10), # VSC frame ID 1
|
||||
(5, 'eggs', 'xyz.py', 2), # VSC frame ID 2
|
||||
])
|
||||
self.send_request(
|
||||
# should NOT match any variable or frame ID
|
||||
variablesReference=12345,
|
||||
name='spam',
|
||||
value='eggs',
|
||||
)
|
||||
received = self.vsc.received
|
||||
|
||||
self.assert_vsc_received(received, [
|
||||
self.expected_failure(''),
|
||||
# no events
|
||||
])
|
||||
|
||||
def test_container(self):
|
||||
with self.launched():
|
||||
with self.hidden():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue