CARVIEW |
Select Language
HTTP/2 200
date: Fri, 10 Oct 2025 19:51:03 GMT
server: Fly/6f91d33b9d (2025-10-08)
content-type: text/html; charset=utf-8
content-encoding: gzip
via: 2 fly.io, 2 fly.io
fly-request-id: 01K77TTHG1C15BJDV2F0THH6KP-bom
Debugging a Click application using pdb | Simon Willison’s TILs
Debugging a Click application using pdb
This tip is for when you are working on a Python command-line application that runs using that program's name, as opposed to typing python my_script.py
. I usually need this when I'm working on applications built using Click, e.g. projects I start using my click-app cookiecutter template.
So you're working on one of these apps and it throws an exception:
% dogsheep-beta index beta.db dogsheep-beta.yml
Traceback (most recent call last):
...
File "/Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/utils.py", line 46, in run_indexer
columns = derive_columns(other_db, sql)
File "/Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/utils.py", line 63, in derive_columns
cursor = db.conn.execute(sql + " limit 0")
sqlite3.OperationalError: near "from": syntax error
You can run the Python debugger against it using python -i $(which dogsheep-beta)
to get an interactive prompt, then import pdb; pdb.pm()
to open the debugger at the last exception:
% python -i $(which dogsheep-beta) index beta.db dogsheep-beta.yml
Traceback (most recent call last):
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/bin/dogsheep-beta", line 11, in <module>
load_entry_point('dogsheep-beta', 'console_scripts', 'dogsheep-beta')()
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/simon/.local/share/virtualenvs/dogsheep-beta-u_po4Rpj/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/cli.py", line 30, in index
run_indexer(db_path, rules, tokenize=None if tokenize == "none" else tokenize)
File "/Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/utils.py", line 46, in run_indexer
columns = derive_columns(other_db, sql)
File "/Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/utils.py", line 63, in derive_columns
cursor = db.conn.execute(sql + " limit 0")
sqlite3.OperationalError: near "from": syntax error
>>> import pdb; pdb.pm()
> /Users/simon/Dropbox/Development/dogsheep-beta/dogsheep_beta/utils.py(63)derive_columns()
-> cursor = db.conn.execute(sql + " limit 0")
(Pdb) print(sql)
...
Related
- python The pdb interact command - 2022-10-31
- docker Running gdb against a Python process in a running Docker container - 2021-03-21
- sqlite Using pysqlite3 on macOS - 2021-07-10
- python Running PyPy on macOS using Homebrew - 2022-09-14
- pytest Testing a Click app with streaming input - 2022-01-09
- python Using the sqlite3 Python module in Pyodide - Python WebAssembly - 2021-10-18
- python macOS Catalina sort-of includes Python 3 - 2020-04-21
- sqlite Loading SQLite extensions in Python on macOS - 2023-01-07
- sqlite Building a specific version of SQLite with pysqlite on macOS/Linux - 2021-08-14
- python Tracing every executed Python statement - 2021-03-21
Created 2020-09-03T10:48:51-07:00, updated 2020-09-03T12:00:52-07:00 · History · Edit