question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugger console prints the key when the key doesn't exist in a dict

See original GitHub issue

Environment data

VS Code version: 1.19.3 Python Extension version: 0.9.1 Python Version: 2.7.12 OS and version: Ubuntu 16.04.3 x64

Actual behavior

The debugger console gives a weird result when indexing a dict with a key that doesn’t exist in the dict. It prints the key… which is confusing and unexpected.

Expected behavior

It prints that the key doesn’t exist. (KeyError)

Steps to reproduce:

  • Debug a file that has a dict, for example:
a = {'a': 123}
  • Type in the debugger console:
>>> a['a']
123
>>> a['b']
'b' # ???

GIF

vscode-bug

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Jan 31, 2018

Thanks, @elliott-beach for verifying!

0reactions
DonJayamannecommented, Feb 1, 2018

Do you know off the top of your head if you can get richer error messages from PTVSD?

This feature is currently not supported, some work was done to add support for this PythonProcessCallbackHandler.ts#L273, but was never comlpeted.

I believe this can be done.

I think this is an issue with the way the debugger handles exceptions.

As a first step, I’d saw we need to ensure the error message (b) is being handled and displayed. Then we can look at supporting rich exceptions.

Oh yes, thanks for identifying the issue in the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The given key was not present in the dictionary. Which key?
Problem here is that the debugger is not always available, for example when reading log file. – Andreas. Oct 7, 2014 at 20:10....
Read more >
Debug mode doesn't print entire dictionary in python - GitHub
Issue Type: Bug. Running a Python script in debug mode will not print the entire dictionary. Just prints partial data.
Read more >
Check whether given Key already exists in a Python Dictionary
This article will be focusing on the Python program to check whether a given key already exists in a dictionary.
Read more >
pdb — The Python Debugger — Python 3.11.1 documentation
Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even...
Read more >
Errors, Logging, and Debugging - Hydro-Informatics
A mapping key is not found. May occur when referencing a non-existing dictionary key. ImportError. Importing a module that does not exist.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found