Sentry is committed to helping developers fix broken code quickly and effectively. In this article, we’ll cover a range of intermediate to advanced

Debugging Python with VS Code and Sentry

submited by
Style Pass
2025-01-06 10:30:05

Sentry is committed to helping developers fix broken code quickly and effectively. In this article, we’ll cover a range of intermediate to advanced techniques for debugging Python code using VS Code and the Sentry Python SDK.

In order to debug, we need some buggy code. So we've prepared a short Python script. This script contains user data from an external JSON file into an internal data structure. Similar code could be used to import user accounts into an email newsletter manager. 

This code will work for initial, simple test cases involving small, perfectly formatted users.json files, but will throw exceptions outside of a perfectly controlled testing environment. Some failure cases: 

In the sections below, we'll use different debugging environments to investigate each of these cases. To follow along, copy-paste the above code to a file named users.py in an empty directory on your system (you will create users.json as part of the steps below).

VS Code provides a graphical debugging interface that can be used with a variety of programming languages, including Python. If you don't already have VS Code on your system, you can find installation files and instructions here. 

Leave a Comment